diff options
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/conditn.cxx | 37 | ||||
-rw-r--r-- | sal/osl/unx/file.cxx | 23 | ||||
-rw-r--r-- | sal/osl/unx/file_misc.cxx | 25 | ||||
-rw-r--r-- | sal/osl/unx/mutex.cxx | 9 | ||||
-rw-r--r-- | sal/osl/unx/pipe.cxx | 27 | ||||
-rw-r--r-- | sal/osl/unx/process.cxx | 11 | ||||
-rw-r--r-- | sal/osl/unx/profile.cxx | 15 | ||||
-rw-r--r-- | sal/osl/unx/socket.cxx | 35 | ||||
-rw-r--r-- | sal/osl/unx/thread.cxx | 19 | ||||
-rw-r--r-- | sal/osl/unx/unixerrnostring.hxx | 27 | ||||
-rw-r--r-- | sal/osl/unx/uunxapi.cxx | 464 |
11 files changed, 586 insertions, 106 deletions
diff --git a/sal/osl/unx/conditn.cxx b/sal/osl/unx/conditn.cxx index 45f1c0e600a2..cede35a86d04 100644 --- a/sal/osl/unx/conditn.cxx +++ b/sal/osl/unx/conditn.cxx @@ -22,6 +22,7 @@ #include <assert.h> #include "system.hxx" +#include "unixerrnostring.hxx" #include <sal/log.hxx> #include <sal/types.h> @@ -53,7 +54,7 @@ oslCondition SAL_CALL osl_createCondition() nRet = pthread_cond_init(&pCond->m_Condition, PTHREAD_CONDATTR_DEFAULT); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "pthread_cond_init failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "pthread_cond_init failed: " << UnixErrnoString(nRet) ); free(pCond); return nullptr; @@ -62,10 +63,10 @@ oslCondition SAL_CALL osl_createCondition() nRet = pthread_mutex_init(&pCond->m_Lock, PTHREAD_MUTEXATTR_DEFAULT); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "pthread_mutex_init failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "pthread_mutex_init failed: " << UnixErrnoString(nRet) ); nRet = pthread_cond_destroy(&pCond->m_Condition); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "pthread_cond_destroy failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "pthread_cond_destroy failed: " << UnixErrnoString(nRet) ); free(pCond); pCond = nullptr; @@ -87,9 +88,9 @@ void SAL_CALL osl_destroyCondition(oslCondition Condition) if ( pCond ) { int nRet = pthread_cond_destroy(&pCond->m_Condition); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "pthread_cond_destroy failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "pthread_cond_destroy failed: " << UnixErrnoString(nRet) ); nRet = pthread_mutex_destroy(&pCond->m_Lock); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "pthread_mutex_destroy failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "pthread_mutex_destroy failed: " << UnixErrnoString(nRet) ); free(Condition); } @@ -106,7 +107,7 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) nRet = pthread_mutex_lock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "osl_setCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "osl_setCondition(" << pCond << "): pthread_mutex_lock failed: " << UnixErrnoString(nRet) ); return false; } @@ -114,7 +115,7 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) nRet = pthread_cond_broadcast(&pCond->m_Condition); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "osl_setCondition(" << pCond << "): pthread_cond_broadcast failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "osl_setCondition(" << pCond << "): pthread_cond_broadcast failed: " << UnixErrnoString(nRet) ); // try to unlock the mutex pthread_mutex_unlock(&pCond->m_Lock); return false; @@ -123,7 +124,7 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) nRet = pthread_mutex_unlock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "osl_setCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "osl_setCondition(" << pCond << "): pthread_mutex_unlock failed: " << UnixErrnoString(nRet) ); return false; } @@ -145,7 +146,7 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) nRet = pthread_mutex_lock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "osl_resetCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "osl_resetCondition(" << pCond << "): pthread_mutex_lock failed: " << UnixErrnoString(nRet) ); return false; } @@ -154,7 +155,7 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) nRet = pthread_mutex_unlock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "osl_resetCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "osl_resetCondition(" << pCond << "): pthread_mutex_unlock failed: " << UnixErrnoString(nRet) ); return false; } @@ -177,7 +178,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time nRet = pthread_mutex_lock(&pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_lock failed: " << UnixErrnoString(nRet) ); return osl_cond_result_error; } @@ -203,7 +204,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time { Result = osl_cond_result_timeout; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << UnixErrnoString(nRet) ); return Result; } @@ -211,7 +212,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time { Result = osl_cond_result_error; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << UnixErrnoString(nRet) ); return Result; } } @@ -226,10 +227,10 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time nRet = pthread_cond_wait(&pCond->m_Condition, &pCond->m_Lock); if ( nRet != 0 ) { - SAL_WARN( "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_cond_wait failed: " << strerror(nRet) ); + SAL_WARN( "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_cond_wait failed: " << UnixErrnoString(nRet) ); Result = osl_cond_result_error; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << UnixErrnoString(nRet) ); return Result; } @@ -237,7 +238,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const Time } nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_waitCondition(" << pCond << "): pthread_mutex_unlock failed: " << UnixErrnoString(nRet) ); SAL_INFO( "sal.osl.condition", "osl_waitCondition(" << pCond << "): " << (Result == osl_cond_result_ok ? "OK" : "ERROR") ); @@ -254,12 +255,12 @@ sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition) pCond = static_cast<oslConditionImpl*>(Condition); nRet = pthread_mutex_lock(&pCond->m_Lock); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_checkCondition(" << pCond << "): pthread_mutex_lock failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_checkCondition(" << pCond << "): pthread_mutex_lock failed: " << UnixErrnoString(nRet) ); State = pCond->m_State; nRet = pthread_mutex_unlock(&pCond->m_Lock); - SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_checkCondition(" << pCond << "): pthread_mutex_unlock failed: " << strerror(nRet) ); + SAL_WARN_IF( nRet != 0, "sal.osl.condition", "osl_checkCondition(" << pCond << "): pthread_mutex_unlock failed: " << UnixErrnoString(nRet) ); SAL_INFO( "sal.osl.condition", "osl_checkCondition(" << pCond << "): " << (State ? "YES" : "NO") ); diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index ae1bc31c9069..9f888579e3a9 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -33,6 +33,7 @@ #include "file_impl.hxx" #include "file_url.hxx" #include "uunxapi.hxx" +#include "unixerrnostring.hxx" #include <algorithm> #include <cassert> @@ -257,7 +258,7 @@ oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize) if (nCurPos == off_t(-1)) { int e = errno; - SAL_INFO("sal.file", "lseek(" << m_fd << ",0,SEEK_CUR): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "lseek(" << m_fd << ",0,SEEK_CUR): " << UnixErrnoString(e)); return result; } else @@ -267,7 +268,7 @@ oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize) if (lseek(m_fd, static_cast<off_t>(nSize - 1), SEEK_SET) == -1) { int e = errno; - SAL_INFO("sal.file", "lseek(" << m_fd << "," << nSize - 1 << ",SEEK_SET): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "lseek(" << m_fd << "," << nSize - 1 << ",SEEK_SET): " << UnixErrnoString(e)); return result; } else @@ -277,7 +278,7 @@ oslFileError FileHandle_Impl::setSize(sal_uInt64 uSize) { /* Failure. Restore saved position */ int e = errno; - SAL_INFO("sal.file", "write(" << m_fd << ",\"\",1): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "write(" << m_fd << ",\"\",1): " << UnixErrnoString(e)); (void) lseek(m_fd, nCurPos, SEEK_SET); return result; } @@ -912,7 +913,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (f == -1) { int e = errno; - SAL_INFO("sal.file", "fcntl(" << fd << ",F_GETFL,0): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fcntl(" << fd << ",F_GETFL,0): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -924,7 +925,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (fcntl(fd, F_SETFL, (f & ~O_NONBLOCK)) == -1) { int e = errno; - SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETFL,(f & ~O_NONBLOCK)): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETFL,(f & ~O_NONBLOCK)): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -940,7 +941,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (fstat(fd, &aFileStat) == -1) { int e = errno; - SAL_INFO("sal.file", "fstat(" << fd << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fstat(" << fd << "): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -964,7 +965,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (flock(fd, LOCK_EX | LOCK_NB) == -1) { int e = errno; - SAL_INFO("sal.file", "flock(" << fd << ",LOCK_EX|LOCK_NB): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "flock(" << fd << ",LOCK_EX|LOCK_NB): " << UnixErrnoString(e)); /* Mac OSX returns ENOTSUP for webdav drives. We should try read lock */ // Restore errno after possibly having been overwritten by the SAL_INFO above... @@ -990,7 +991,7 @@ oslFileError openFilePath(const char *cpFilePath, oslFileHandle* pHandle, sal_uI if (fcntl(fd, F_SETLK, &aflock) == -1) { int e = errno; - SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETLK): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fcntl(" << fd << ",F_SETLK): " << UnixErrnoString(e)); eRet = oslTranslateFileError(e); (void) close(fd); SAL_INFO("sal.file", "close(" << fd << ")"); @@ -1070,7 +1071,7 @@ oslFileError SAL_CALL osl_closeFile(oslFileHandle Handle) else if (close(pImpl->m_fd) == -1) { int e = errno; - SAL_INFO("sal.file", "close(" << pImpl->m_fd << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "close(" << pImpl->m_fd << "): " << UnixErrnoString(e)); /* translate error code */ result = oslTranslateFileError(e); } @@ -1102,7 +1103,7 @@ oslFileError SAL_CALL osl_syncFile(oslFileHandle Handle) if (fsync(pImpl->m_fd) == -1) { int e = errno; - SAL_INFO("sal.file", "fsync(" << pImpl->m_fd << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "fsync(" << pImpl->m_fd << "): " << UnixErrnoString(e)); return oslTranslateFileError(e); } else @@ -1204,7 +1205,7 @@ oslFileError SAL_CALL osl_mapFile( #elif defined __sun if (madvise(static_cast< caddr_t >(p), nLength, MADV_WILLNEED) != 0) - SAL_INFO("sal.file", "madvise(..., MADV_WILLNEED) failed with " << strerror(errno)); + SAL_INFO("sal.file", "madvise(..., MADV_WILLNEED) failed with " << UnixErrnoString(errno)); #endif } diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index a45d32e4c79e..05e72997070b 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -34,6 +34,7 @@ #include "file_url.hxx" #include "uunxapi.hxx" #include "readwrite_helper.hxx" +#include "unixerrnostring.hxx" #include <sys/types.h> #include <errno.h> @@ -217,7 +218,7 @@ oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirect else { int e = errno; - SAL_INFO("sal.file", "opendir(" << path << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "opendir(" << path << "): " << UnixErrnoString(e)); // Restore errno after possible modification by SAL_INFO above errno = e; } @@ -250,7 +251,7 @@ oslFileError SAL_CALL osl_closeDirectory(oslDirectory pDirectory) if (closedir( pDirImpl->pDirStruct) != 0) { int e = errno; - SAL_INFO("sal.file", "closedir(" << pDirImpl->pDirStruct << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "closedir(" << pDirImpl->pDirStruct << "): " << UnixErrnoString(e)); err = oslTranslateFileError(e); } else @@ -470,7 +471,7 @@ oslFileError osl_psz_createDirectory(char const * pszPath, sal_uInt32 flags) if ( nRet < 0 ) { nRet=errno; - SAL_INFO("sal.file", "mkdir(" << pszPath << ",0" << std::oct << mode << std::dec << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "mkdir(" << pszPath << ",0" << std::oct << mode << std::dec << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -488,7 +489,7 @@ static oslFileError osl_psz_removeDirectory( const sal_Char* pszPath ) if ( nRet < 0 ) { nRet=errno; - SAL_INFO("sal.file", "rmdir(" << pszPath << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "rmdir(" << pszPath << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -712,7 +713,7 @@ static oslFileError osl_unlinkFile(const sal_Char* pszPath) if (nRet < 0) { nRet=errno; - SAL_INFO("sal.file", "unlink(" << pszPath << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "unlink(" << pszPath << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -730,7 +731,7 @@ static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* ps if (nRet < 0) { nRet=errno; - SAL_INFO("sal.file", "rename(" << pszPath << "," << pszDestPath << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "rename(" << pszPath << "," << pszDestPath << "): " << UnixErrnoString(nRet)); return oslTranslateFileError(nRet); } else @@ -820,7 +821,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* { int e = errno; SAL_INFO("sal.file", "rename(" << pszDestFileName << ", " << tmpDestFile - << "): errno " << e << ": " << strerror(e)); + << "): " << UnixErrnoString(e)); if (e == ENOENT) { DestFileExists = 0; @@ -859,7 +860,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* if (unlink(pszDestFileName) != 0) { int e = errno; - SAL_INFO("sal.file", "unlink(" << pszDestFileName << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "unlink(" << pszDestFileName << "): " << UnixErrnoString(e)); } else SAL_INFO("sal.file", "unlink(" << pszDestFileName << "): OK"); @@ -868,7 +869,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* { int e = errno; SAL_INFO("sal.file", "rename(" << tmpDestFile << ", " << pszDestFileName - << "): errno " << e << ": " << strerror(e)); + << "): " << UnixErrnoString(e)); } else SAL_INFO("sal.file", "rename(" << tmpDestFile << ", " << pszDestFileName << "): OK"); @@ -898,7 +899,7 @@ void attemptChangeMetadata( const sal_Char* pszFileName, mode_t nMode, time_t nA #endif { int e = errno; - SAL_INFO("sal.file", "chmod(" << pszFileName << ",0" << std::oct << nMode << std::dec <<"): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "chmod(" << pszFileName << ",0" << std::oct << nMode << std::dec <<"): " << UnixErrnoString(e)); } else SAL_INFO("sal.file", "chmod(" << pszFileName << ",0" << std::oct << nMode << std::dec <<"): OK"); @@ -979,7 +980,7 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD if ( DestFileFD < 0 ) { nRet=errno; - SAL_INFO("sal.file", "open(" << pszDestFileName << ",O_WRONLY|O_CREAT,0" << std::oct << mode << std::dec << "): errno " << nRet << ": " << strerror(nRet)); + SAL_INFO("sal.file", "open(" << pszDestFileName << ",O_WRONLY|O_CREAT,0" << std::oct << mode << std::dec << "): " << UnixErrnoString(nRet)); osl_closeFile(SourceFileFH); return nRet; } @@ -1023,7 +1024,7 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD if ( close( DestFileFD ) == -1 ) { int e = errno; - SAL_INFO("sal.file", "close(" << DestFileFD << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "close(" << DestFileFD << "): " << UnixErrnoString(e)); if ( nRet == 0 ) nRet = e; } diff --git a/sal/osl/unx/mutex.cxx b/sal/osl/unx/mutex.cxx index 570b452a4cfa..72c36f5eb9ab 100644 --- a/sal/osl/unx/mutex.cxx +++ b/sal/osl/unx/mutex.cxx @@ -24,6 +24,7 @@ #endif #endif #include "system.hxx" +#include "unixerrnostring.hxx" #include <sal/log.hxx> #include <osl/mutex.h> @@ -57,7 +58,7 @@ oslMutex SAL_CALL osl_createMutex() nRet = pthread_mutex_init(&(pMutex->mutex), &aMutexAttr); if ( nRet != 0 ) { - SAL_WARN("sal.osl.mutex", "pthread_muxex_init failed: " << strerror(nRet)); + SAL_WARN("sal.osl.mutex", "pthread_muxex_init failed: " << UnixErrnoString(nRet)); free(pMutex); pMutex = nullptr; @@ -79,7 +80,7 @@ void SAL_CALL osl_destroyMutex(oslMutexImpl *pMutex) nRet = pthread_mutex_destroy(&(pMutex->mutex)); if ( nRet != 0 ) { - SAL_WARN("sal.osl.mutex", "pthread_mutex_destroy failed: " << strerror(nRet)); + SAL_WARN("sal.osl.mutex", "pthread_mutex_destroy failed: " << UnixErrnoString(nRet)); } free(pMutex); @@ -97,7 +98,7 @@ sal_Bool SAL_CALL osl_acquireMutex(oslMutexImpl *pMutex) nRet = pthread_mutex_lock(&(pMutex->mutex)); if ( nRet != 0 ) { - SAL_WARN("sal.osl.mutex", "pthread_mutex_lock failed: " << strerror(nRet)); + SAL_WARN("sal.osl.mutex", "pthread_mutex_lock failed: " << UnixErrnoString(nRet)); return false; } return true; @@ -134,7 +135,7 @@ sal_Bool SAL_CALL osl_releaseMutex(oslMutexImpl *pMutex) nRet = pthread_mutex_unlock(&(pMutex->mutex)); if ( nRet != 0 ) { - SAL_WARN("sal.osl.mutex", "pthread_mutex_unlock failed: " << strerror(nRet)); + SAL_WARN("sal.osl.mutex", "pthread_mutex_unlock failed: " << UnixErrnoString(nRet)); return false; } diff --git a/sal/osl/unx/pipe.cxx b/sal/osl/unx/pipe.cxx index 5d80168927a1..3af20aad5284 100644 --- a/sal/osl/unx/pipe.cxx +++ b/sal/osl/unx/pipe.cxx @@ -30,6 +30,7 @@ #include "sockimpl.hxx" #include "secimpl.hxx" +#include "unixerrnostring.hxx" #include <cassert> @@ -222,7 +223,7 @@ static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Op pPipe->m_Socket = socket(AF_UNIX, SOCK_STREAM, 0); if (pPipe->m_Socket < 0) { - SAL_WARN("sal.osl.pipe", "socket() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "socket() failed: " << UnixErrnoString(errno)); destroyPipeImpl(pPipe); return nullptr; } @@ -233,7 +234,7 @@ static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Op Flags |= FD_CLOEXEC; if (fcntl(pPipe->m_Socket, F_SETFD, Flags) == -1) { - SAL_WARN("sal.osl.pipe", "fcntl() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "fcntl() failed: " << UnixErrnoString(errno)); } } @@ -270,7 +271,7 @@ static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Op /* ok, fs clean */ if (bind(pPipe->m_Socket, reinterpret_cast< sockaddr* >(&addr), len) < 0) { - SAL_WARN("sal.osl.pipe", "bind() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "bind() failed: " << UnixErrnoString(errno)); close(pPipe->m_Socket); destroyPipeImpl(pPipe); return nullptr; @@ -286,7 +287,7 @@ static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Op if (listen(pPipe->m_Socket, 5) < 0) { - SAL_WARN("sal.osl.pipe", "listen() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "listen() failed: " << UnixErrnoString(errno)); // cid#1255391 warns about unlink(name) after stat(name, &status) // above, but the intervening call to bind makes those two clearly // unrelated, as it would fail if name existed at that point in @@ -307,7 +308,7 @@ static oslPipe osl_psz_createPipe(const sal_Char *pszPipeName, oslPipeOptions Op if (connect(pPipe->m_Socket, reinterpret_cast< sockaddr* >(&addr), len) >= 0) return pPipe; - SAL_WARN("sal.osl.pipe", "connect() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "connect() failed: " << UnixErrnoString(errno)); } close (pPipe->m_Socket); @@ -361,7 +362,7 @@ void SAL_CALL osl_closePipe(oslPipe pPipe) int fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd < 0) { - SAL_WARN("sal.osl.pipe", "socket() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "socket() failed: " << UnixErrnoString(errno)); return; } @@ -374,7 +375,7 @@ void SAL_CALL osl_closePipe(oslPipe pPipe) nRet = connect(fd, reinterpret_cast< sockaddr* >(&addr), sizeof(addr)); if (nRet < 0) - SAL_WARN("sal.osl.pipe", "connect() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "connect() failed: " << UnixErrnoString(errno)); close(fd); } @@ -382,11 +383,11 @@ void SAL_CALL osl_closePipe(oslPipe pPipe) nRet = shutdown(ConnFD, 2); if (nRet < 0) - SAL_WARN("sal.osl.pipe", "shutdown() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "shutdown() failed: " << UnixErrnoString(errno)); nRet = close(ConnFD); if (nRet < 0) - SAL_WARN("sal.osl.pipe", "close() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "close() failed: " << UnixErrnoString(errno)); /* remove filesystem entry */ if (strlen(pPipe->m_Name) > 0) @@ -418,7 +419,7 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe) if (s < 0) { - SAL_WARN("sal.osl.pipe", "accept() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "accept() failed: " << UnixErrnoString(errno)); return nullptr; } @@ -446,7 +447,7 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe) { flags |= FD_CLOEXEC; if (fcntl(s, F_SETFD, flags) < 0) - SAL_WARN("sal.osl.pipe", "fcntl() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "fcntl() failed: " << UnixErrnoString(errno)); } pAcceptedPipe->m_Socket = s; @@ -471,7 +472,7 @@ sal_Int32 SAL_CALL osl_receivePipe(oslPipe pPipe, nRet = recv(pPipe->m_Socket, pBuffer, BytesToRead, 0); if (nRet < 0) - SAL_WARN("sal.osl.pipe", "recv() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "recv() failed: " << UnixErrnoString(errno)); return nRet; } @@ -493,7 +494,7 @@ sal_Int32 SAL_CALL osl_sendPipe(oslPipe pPipe, nRet = send(pPipe->m_Socket, pBuffer, BytesToSend, 0); if (nRet <= 0) - SAL_WARN("sal.osl.pipe", "send() failed: " << strerror(errno)); + SAL_WARN("sal.osl.pipe", "send() failed: " << UnixErrnoString(errno)); return nRet; } diff --git a/sal/osl/unx/process.cxx b/sal/osl/unx/process.cxx index b88e5246d1a7..480bb264a267 100644 --- a/sal/osl/unx/process.cxx +++ b/sal/osl/unx/process.cxx @@ -41,6 +41,7 @@ #endif #include "system.hxx" +#include "unixerrnostring.hxx" #if defined(__sun) # include <sys/procfs.h> #endif @@ -174,7 +175,7 @@ static void ChildStatusProc(void *pData) OSL_ASSERT(geteuid() == 0); /* must be root */ if (! INIT_GROUPS(data.m_name, data.m_gid) || (setuid(data.m_uid) != 0)) - SAL_WARN("sal.osl", "Failed to change uid and guid, errno=" << errno << " (" << strerror(errno) << ")" ); + SAL_WARN("sal.osl", "Failed to change uid and guid: " << UnixErrnoString(errno)); const rtl::OUString envVar("HOME"); osl_clearEnvironment(envVar.pData); @@ -234,14 +235,14 @@ static void ChildStatusProc(void *pData) execv(data.m_pszArgs[0], const_cast<char **>(data.m_pszArgs)); } - SAL_WARN("sal.osl", "Failed to exec, errno=" << errno << " (" << strerror(errno) << ")"); + SAL_WARN("sal.osl", "Failed to exec: " << UnixErrnoString(errno)); SAL_WARN("sal.osl", "ChildStatusProc : starting '" << data.m_pszArgs[0] << "' failed"); /* if we reach here, something went wrong */ errno_copy = errno; if ( !safeWrite(channel[1], &errno_copy, sizeof(errno_copy)) ) - SAL_WARN("sal.osl", "sendFdPipe : sending failed (" << strerror(errno) << ")"); + SAL_WARN("sal.osl", "sendFdPipe : sending failed: " << UnixErrnoString(errno)); if ( channel[1] != -1 ) close(channel[1]); @@ -300,7 +301,7 @@ static void ChildStatusProc(void *pData) if ( child_pid < 0) { - SAL_WARN("sal.osl", "Failed to wait for child process, errno=" << errno << " (" << strerror(errno) << ")"); + SAL_WARN("sal.osl", "Failed to wait for child process: " << UnixErrnoString(errno)); /* We got another error than EINTR. Anyway we have to wake up the @@ -341,7 +342,7 @@ static void ChildStatusProc(void *pData) else { SAL_WARN("sal.osl", "ChildStatusProc : starting '" << data.m_pszArgs[0] << "' failed"); - SAL_WARN("sal.osl", "Failed to launch child process, child reports errno=" << status << " (" << strerror(status) << ")"); + SAL_WARN("sal.osl", "Failed to launch child process, child reports " << UnixErrnoString(status)); /* Close pipe ends */ if ( pdata->m_pInputWrite ) diff --git a/sal/osl/unx/profile.cxx b/sal/osl/unx/profile.cxx index 6af40898a58c..a986dfd0d41f 100644 --- a/sal/osl/unx/profile.cxx +++ b/sal/osl/unx/profile.cxx @@ -20,6 +20,7 @@ #include "system.hxx" #include "readwrite_helper.hxx" #include "file_url.hxx" +#include "unixerrnostring.hxx" #include <osl/diagnose.h> #include <osl/profile.h> @@ -334,7 +335,7 @@ static bool writeProfileImpl(osl_TFile* pFile) if ( !safeWrite(pFile->m_Handle, pFile->m_pWriteBuf, pFile->m_nWriteBufLen - pFile->m_nWriteBufFree) ) { - SAL_INFO("sal.osl", "write failed " << strerror(errno)); + SAL_INFO("sal.osl", "write failed: " << UnixErrnoString(errno)); return false; } @@ -928,7 +929,7 @@ static bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode) if ( fcntl(pFile->m_Handle, F_SETLKW, &lock) == -1 && errno != ENOTSUP ) #endif { - SAL_INFO("sal.osl", "fcntl returned -1 (" << strerror(errno) << ")"); + SAL_INFO("sal.osl", "fcntl failed: " << UnixErrnoString(errno)); return false; } @@ -953,7 +954,7 @@ static osl_TFile* openFileImpl(const sal_Char* pszFilename, oslProfileOption Pro if (pFile->m_Handle == -1) { int e = errno; - SAL_INFO("sal.file", "open(" << pszFilename << ",O_RDONLY): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "open(" << pszFilename << ",O_RDONLY): " << UnixErrnoString(e)); } else SAL_INFO("sal.file", "open(" << pszFilename << ",O_RDONLY) => " << pFile->m_Handle); @@ -967,7 +968,7 @@ static osl_TFile* openFileImpl(const sal_Char* pszFilename, oslProfileOption Pro ((pFile->m_Handle = open(pszFilename, O_RDWR)) < 0)) { int e = errno; - SAL_INFO("sal.file", "open(" << pszFilename << ",...): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "open(" << pszFilename << ",...): " << UnixErrnoString(e)); free(pFile); return nullptr; } @@ -1079,7 +1080,7 @@ static sal_Char* OslProfile_getLine(osl_TFile* pFile) if ((Max = read(pFile->m_Handle, &pFile->m_ReadBuf[Bytes], Free)) < 0) { - SAL_INFO("sal.osl", "read failed " << strerror(errno)); + SAL_INFO("sal.osl", "read failed: " << UnixErrnoString(errno)); if( pLine ) free( pLine ); @@ -1728,7 +1729,7 @@ static bool osl_ProfileSwapProfileNames(osl_TProfileImpl* pProfile) if (!result) { int e = errno; - SAL_INFO("sal.file", "rename(" << pProfile->m_FileName << "," << pszBakFile << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "rename(" << pProfile->m_FileName << "," << pszBakFile << "): " << UnixErrnoString(e)); } else { @@ -1737,7 +1738,7 @@ static bool osl_ProfileSwapProfileNames(osl_TProfileImpl* pProfile) if (!result) { int e = errno; - SAL_INFO("sal.file", "rename(" << pszTmpFile << "," << pProfile->m_FileName << "): errno " << e << ": " << strerror(e)); + SAL_INFO("sal.file", "rename(" << pszTmpFile << "," << pProfile->m_FileName << "): " << UnixErrnoString(e)); } else { diff --git a/sal/osl/unx/socket.cxx b/sal/osl/unx/socket.cxx index 05a6234f64df..698de982e181 100644 --- a/sal/osl/unx/socket.cxx +++ b/sal/osl/unx/socket.cxx @@ -30,6 +30,7 @@ #include <sal/log.hxx> #include "sockimpl.hxx" +#include "unixerrnostring.hxx" /* defines for poll */ #ifdef HAVE_POLL_H @@ -1179,7 +1180,7 @@ oslSocket SAL_CALL osl_createSocket( if(pSocket->m_Socket == OSL_INVALID_SOCKET) { int nErrno = errno; - SAL_WARN( "sal.osl", "socket creation failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "socket creation failed: " << UnixErrnoString(nErrno) ); destroySocketImpl(pSocket); pSocket= nullptr; @@ -1195,7 +1196,7 @@ oslSocket SAL_CALL osl_createSocket( { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "failed changing socket flags: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "failed changing socket flags: " << UnixErrnoString(nErrno) ); } } else @@ -1258,7 +1259,7 @@ void SAL_CALL osl_closeSocket(oslSocket pSocket) if (nRet < 0) { int nErrno = errno; - SAL_WARN( "sal.osl", "getsockname call failed with error: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "getsockname call failed: " << UnixErrnoString(nErrno) ); } if (s.aSockAddr.sa_family == AF_INET) @@ -1272,7 +1273,7 @@ void SAL_CALL osl_closeSocket(oslSocket pSocket) if (nConnFD < 0) { int nErrno = errno; - SAL_WARN( "sal.osl", "socket call failed with error: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "socket call failed: " << UnixErrnoString(nErrno) ); } else { @@ -1280,7 +1281,7 @@ void SAL_CALL osl_closeSocket(oslSocket pSocket) if (nRet < 0) { int nErrno = errno; - SAL_WARN( "sal.osl", "connect call failed with error: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "connect call failed: " << UnixErrnoString(nErrno) ); } close(nConnFD); } @@ -1294,7 +1295,7 @@ void SAL_CALL osl_closeSocket(oslSocket pSocket) { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "closeSocket close error: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "closeSocket close failed: " << UnixErrnoString(nErrno) ); } pSocket->m_Socket = OSL_INVALID_SOCKET; @@ -1427,7 +1428,7 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket, pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "connection failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "connection failed: " << UnixErrnoString(nErrno) ); return osl_Socket_Error; } @@ -1451,7 +1452,7 @@ oslSocketResult SAL_CALL osl_connectSocketTo(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "connection failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "connection failed: " << UnixErrnoString(nErrno) ); osl_enableNonBlockingMode(pSocket, false); return osl_Socket_Error; @@ -1559,7 +1560,7 @@ oslSocket SAL_CALL osl_acceptConnectionOnSocket(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "accept connection failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "accept connection failed: " << UnixErrnoString(nErrno) ); #if defined(CLOSESOCKET_DOESNT_WAKE_UP_ACCEPT) pSocket->m_bIsAccepting = false; @@ -1594,7 +1595,7 @@ oslSocket SAL_CALL osl_acceptConnectionOnSocket(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "failed changing socket flags: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "fcntl failed: " << UnixErrnoString(nErrno) ); } } @@ -1636,7 +1637,7 @@ sal_Int32 SAL_CALL osl_receiveSocket(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "receive socket [" << nRead << "] failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "receive socket [" << nRead << "] failed: " << UnixErrnoString(nErrno) ); } else if ( nRead == 0 ) { @@ -1680,7 +1681,7 @@ sal_Int32 SAL_CALL osl_receiveFromSocket(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "receive socket [" << nRead << "] failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "receive socket [" << nRead << "] failed: " << UnixErrnoString(nErrno) ); } else if ( nRead == 0 ) { @@ -1717,7 +1718,7 @@ sal_Int32 SAL_CALL osl_sendSocket(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "send socket [" << nWritten << "] failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "send socket [" << nWritten << "] failed: " << UnixErrnoString(nErrno) ); } else if ( nWritten == 0 ) { @@ -1765,7 +1766,7 @@ sal_Int32 SAL_CALL osl_sendToSocket(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "send socket [" << nWritten << "] failed: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "send socket [" << nWritten << "] failed: " << UnixErrnoString(nErrno) ); } else if ( nWritten == 0 ) { @@ -1871,7 +1872,7 @@ static bool socket_poll ( { pSocket->m_nLastError = errno; int nErrno = errno; - SAL_WARN( "sal.osl", "poll error: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "poll failed: " << UnixErrnoString(nErrno) ); return false; } if (result == 0) @@ -1921,7 +1922,7 @@ static sal_Bool socket_poll ( { pSocket->m_nLastError = errno; int nErrno = errno; - SAL_WARN( "sal.osl", "select error: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "select failed: " << UnixErrnoString(nErrno) ); return sal_False; } if (result == 0) @@ -1992,7 +1993,7 @@ sal_Bool SAL_CALL osl_shutdownSocket(oslSocket pSocket, { pSocket->m_nLastError=errno; int nErrno = errno; - SAL_WARN( "sal.osl", "socket shutdown error: (" << nErrno << ") " << strerror(nErrno) ); + SAL_WARN( "sal.osl", "shutdown failed: " << UnixErrnoString(nErrno) ); } return (nRet==0); } diff --git a/sal/osl/unx/thread.cxx b/sal/osl/unx/thread.cxx index a47ab7d317c5..8fbe04e46d91 100644 --- a/sal/osl/unx/thread.cxx +++ b/sal/osl/unx/thread.cxx @@ -24,6 +24,7 @@ #include <functional> #include "system.hxx" +#include "unixerrnostring.hxx" #include <string.h> #if defined(OPENBSD) #include <sched.h> @@ -292,8 +293,7 @@ static oslThread osl_thread_create_Impl ( { SAL_WARN( "sal.osl", - "pthread_create failed with " << nRet << " \"" << strerror(nRet) - << "\""); + "pthread_create failed: " << UnixErrnoString(nRet)); pthread_mutex_unlock (&(pImpl->m_Lock)); osl_thread_destruct_Impl (&pImpl); @@ -732,8 +732,7 @@ static void osl_thread_priority_init_Impl() { SAL_WARN( "sal.osl", - "pthread_getschedparam failed with " << nRet << " \"" - << strerror(nRet) << "\""); + "pthread_getschedparam failed: " << UnixErrnoString(nRet)); return; } @@ -758,8 +757,7 @@ static void osl_thread_priority_init_Impl() int e = errno; SAL_WARN( "sal.osl", - "sched_get_priority_min failed with " << e << " \"" << strerror(e) - << "\""); + "sched_get_priority_min failed: " << UnixErrnoString(e)); } if ((nRet = sched_get_priority_max(policy) ) != -1) @@ -773,8 +771,7 @@ static void osl_thread_priority_init_Impl() int e = errno; SAL_WARN( "sal.osl", - "sched_get_priority_max failed with " << e << " \"" << strerror(e) - << "\""); + "sched_get_priority_max failed: " << UnixErrnoString(e)); } g_thread.m_priority.m_Normal = @@ -792,8 +789,7 @@ static void osl_thread_priority_init_Impl() { SAL_WARN( "sal.osl", - "pthread_setschedparam failed with " << nRet << " \"" - << strerror(nRet) << "\""); + "pthread_setschedparam failed: " << UnixErrnoString(nRet)); SAL_INFO( "sal.osl", "Thread ID " << pthread_self() << ", Policy " << policy @@ -887,8 +883,7 @@ void SAL_CALL osl_setThreadPriority ( { SAL_WARN( "sal.osl", - "pthread_setschedparam failed with " << nRet << " \"" - << strerror(nRet) << "\""); + "pthread_setschedparam failed: " << UnixErrnoString(nRet)); } #endif /* NO_PTHREAD_PRIORITY */ diff --git a/sal/osl/unx/unixerrnostring.hxx b/sal/osl/unx/unixerrnostring.hxx new file mode 100644 index 000000000000..9e13b04e6c4e --- /dev/null +++ b/sal/osl/unx/unixerrnostring.hxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SAL_OSL_UNX_UNIXERRNOSTRING_HXX +#define INCLUDED_SAL_OSL_UNX_UNIXERRNOSTRING_HXX + +#include <string> + +// Return the symbolic name of an errno value, like "ENOENT". + +// Rationale why to use this and not strerror(): This is intended to be used in SAL_INFO() and +// SAL_WARN(). Such messages are intended to be read by developers, not end-users. Developers are +// (or should be) familiar with symbolic errno names in code anyway. strerror() is localized and the +// localised error strings might be less familiar to a developer that happens to run a localised +// environment. + +std::string UnixErrnoString(int nErrno); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx index 614c83c04e34..a9aaa1f29564 100644 --- a/sal/osl/unx/uunxapi.cxx +++ b/sal/osl/unx/uunxapi.cxx @@ -21,6 +21,7 @@ #include "uunxapi.hxx" #include "system.hxx" +#include "unixerrnostring.hxx" #include <limits.h> #include <rtl/ustring.hxx> #include <osl/thread.h> @@ -183,7 +184,7 @@ int access_u(const rtl_uString* pustrPath, int mode) int result = access(fn.getStr(), mode); int saved_errno = errno; if (result == -1) - SAL_INFO("sal.file", "access(" << fn.getStr() << ",0" << std::oct << mode << std::dec << "): errno " << saved_errno << ": " << strerror(saved_errno)); + SAL_INFO("sal.file", "access(" << fn.getStr() << ",0" << std::oct << mode << std::dec << "): " << UnixErrnoString(saved_errno)); else SAL_INFO("sal.file", "access(" << fn.getStr() << ",0" << std::oct << mode << std::dec << "): OK"); @@ -220,7 +221,7 @@ bool realpath_u(const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedNa bool bRet = realpath(fn.getStr(), rp); int saved_errno = errno; if (!bRet) - SAL_INFO("sal.file", "realpath(" << fn.getStr() << "): errno " << saved_errno << ": " << strerror(saved_errno)); + SAL_INFO("sal.file", "realpath(" << fn.getStr() << "): " << UnixErrnoString(saved_errno)); else SAL_INFO("sal.file", "realpath(" << fn.getStr() << "): OK"); @@ -253,7 +254,7 @@ int stat_c(const char* cpPath, struct stat* buf) int result = stat(cpPath, buf); int saved_errno = errno; if (result == -1) - SAL_INFO("sal.file", "stat(" << cpPath << "): errno " << saved_errno << ": " << strerror(saved_errno)); + SAL_INFO("sal.file", "stat(" << cpPath << "): " << UnixErrnoString(saved_errno)); else SAL_INFO("sal.file", "stat(" << cpPath << "): OK"); @@ -278,7 +279,7 @@ int lstat_c(const char* cpPath, struct stat* buf) int result = lstat(cpPath, buf); int saved_errno = errno; if (result == -1) - SAL_INFO("sal.file", "lstat(" << cpPath << "): errno " << saved_errno << ": " << strerror(saved_errno)); + SAL_INFO("sal.file", "lstat(" << cpPath << "): " << UnixErrnoString(saved_errno)); else SAL_INFO("sal.file", "lstat(" << cpPath << "): OK"); @@ -309,7 +310,7 @@ int mkdir_u(const rtl_uString* path, mode_t mode) int result = mkdir(OUStringToOString(path).getStr(), mode); int saved_errno = errno; if (result == -1) - SAL_INFO("sal.file", "mkdir(" << OUStringToOString(path).getStr() << ",0" << std::oct << mode << std::dec << "): errno " << saved_errno << ": " << strerror(saved_errno)); + SAL_INFO("sal.file", "mkdir(" << OUStringToOString(path).getStr() << ",0" << std::oct << mode << std::dec << "): " << UnixErrnoString(saved_errno)); else SAL_INFO("sal.file", "mkdir(" << OUStringToOString(path).getStr() << ",0" << std::oct << mode << std::dec << "): OK"); @@ -327,7 +328,7 @@ int open_c(const char *cpPath, int oflag, int mode) int result = open(cpPath, oflag, mode); int saved_errno = errno; if (result == -1) - SAL_INFO("sal.file", "open(" << cpPath << ",0" << std::oct << oflag << ",0" << mode << std::dec << "): errno " << saved_errno << ": " << strerror(saved_errno)); + SAL_INFO("sal.file", "open(" << cpPath << ",0" << std::oct << oflag << ",0" << mode << std::dec << "): " << UnixErrnoString(saved_errno)); else SAL_INFO("sal.file", "open(" << cpPath << ",0" << std::oct << oflag << ",0" << mode << std::dec << ") => " << result); @@ -398,7 +399,7 @@ int ftruncate_with_name(int fd, sal_uInt64 uSize, rtl_String* path) int result = ftruncate(fd, uSize); int saved_errno = errno; if (result < 0) - SAL_INFO("sal.file", "ftruncate(" << fd << "," << uSize << "): errno " << saved_errno << ": " << strerror(saved_errno)); + SAL_INFO("sal.file", "ftruncate(" << fd << "," << uSize << "): " << UnixErrnoString(saved_errno)); else SAL_INFO("sal.file", "ftruncate(" << fd << "," << uSize << "): OK"); @@ -409,4 +410,453 @@ int ftruncate_with_name(int fd, sal_uInt64 uSize, rtl_String* path) return result; } + +std::string UnixErrnoString(int nErrno) +{ + // Errnos from <asm-generic/errno-base.h> and <asm-generic/errno.h> on Linux and <sys/errno.h> + // on macOS. + switch (nErrno) + { + case EPERM: + return "EPERM"; + case ENOENT: + return "ENOENT"; + case ESRCH: + return "ESRCH"; + case EINTR: + return "EINTR"; + case EIO: + return "EIO"; + case ENXIO: + return "ENXIO"; + case E2BIG: + return "E2BIG"; + case ENOEXEC: + return "ENOEXEC"; + case EBADF: + return "EBADF"; + case ECHILD: + return "ECHILD"; + case EAGAIN: + return "EAGAIN"; + case ENOMEM: + return "ENOMEM"; + case EACCES: + return "EACCES"; + case EFAULT: + return "EFAULT"; + case ENOTBLK: + return "ENOTBLK"; + case EBUSY: + return "EBUSY"; + case EEXIST: + return "EEXIST"; + case EXDEV: + return "EXDEV"; + case ENODEV: + return "ENODEV"; + case ENOTDIR: + return "ENOTDIR"; + case EISDIR: + return "EISDIR"; + case EINVAL: + return "EINVAL"; + case ENFILE: + return "ENFILE"; + case EMFILE: + return "EMFILE"; + case ENOTTY: + return "ENOTTY"; + case ETXTBSY: + return "ETXTBSY"; + case EFBIG: + return "EFBIG"; + case ENOSPC: + return "ENOSPC"; + case ESPIPE: + return "ESPIPE"; + case EROFS: + return "EROFS"; + case EMLINK: + return "EMLINK"; + case EPIPE: + return "EPIPE"; + case EDOM: + return "EDOM"; + case ERANGE: + return "ERANGE"; + case EDEADLK: + return "EDEADLK"; + case ENAMETOOLONG: + return "ENAMETOOLONG"; + case ENOLCK: + return "ENOLCK"; + case ENOSYS: + return "ENOSYS"; + case ENOTEMPTY: + return "ENOTEMPTY"; + case ELOOP: + return "ELOOP"; + case ENOMSG: + return "ENOMSG"; + case EIDRM: + return "EIDRM"; +#ifdef ECHRNG + case ECHRNG: + return "ECHRNG"; +#endif +#ifdef EL2NSYNC + case EL2NSYNC: + return "EL2NSYNC"; +#endif +#ifdef EL3HLT + case EL3HLT: + return "EL3HLT"; +#endif +#ifdef EL3RST + case EL3RST: + return "EL3RST"; +#endif +#ifdef ELNRNG + case ELNRNG: + return "ELNRNG"; +#endif +#ifdef EUNATCH + case EUNATCH: + return "EUNATCH"; +#endif +#ifdef ENOCSI + case ENOCSI: + return "ENOCSI"; +#endif +#ifdef EL2HLT + case EL2HLT: + return "EL2HLT"; +#endif +#ifdef EBADE + case EBADE: + return "EBADE"; +#endif +#ifdef EBADR + case EBADR: + return "EBADR"; +#endif +#ifdef EXFULL + case EXFULL: + return "EXFULL"; +#endif +#ifdef ENOANO + case ENOANO: + return "ENOANO"; +#endif +#ifdef EBADRQC + case EBADRQC: + return "EBADRQC"; +#endif +#ifdef EBADSLT + case EBADSLT: + return "EBADSLT"; +#endif +#ifdef EBFONT + case EBFONT: + return "EBFONT"; +#endif + case ENOSTR: + return "ENOSTR"; + case ENODATA: + return "ENODATA"; + case ETIME: + return "ETIME"; + case ENOSR: + return "ENOSR"; +#ifdef ENONET + case ENONET: + return "ENONET"; +#endif +#ifdef ENOPKG + case ENOPKG: + return "ENOPKG"; +#endif +#ifdef EREMOTE + case EREMOTE: + return "EREMOTE"; +#endif + case ENOLINK: + return "ENOLINK"; +#ifdef EADV + case EADV: + return "EADV"; +#endif +#ifdef ESRMNT + case ESRMNT: + return "ESRMNT"; +#endif +#ifdef ECOMM + case ECOMM: + return "ECOMM"; +#endif + case EPROTO: + return "EPROTO"; + case EMULTIHOP: + return "EMULTIHOP"; +#ifdef EDOTDOT + case EDOTDOT: + return "EDOTDOT"; +#endif + case EBADMSG: + return "EBADMSG"; + case EOVERFLOW: + return "EOVERFLOW"; +#ifdef ENOTUNIQ + case ENOTUNIQ: + return "ENOTUNIQ"; +#endif +#ifdef EBADFD + case EBADFD: + return "EBADFD"; +#endif +#ifdef EREMCHG + case EREMCHG: + return "EREMCHG"; +#endif +#ifdef ELIBACC + case ELIBACC: + return "ELIBACC"; +#endif +#ifdef ELIBBAD + case ELIBBAD: + return "ELIBBAD"; +#endif +#ifdef ELIBSCN + case ELIBSCN: + return "ELIBSCN"; +#endif +#ifdef ELIBMAX + case ELIBMAX: + return "ELIBMAX"; +#endif +#ifdef ELIBEXEC + case ELIBEXEC: + return "ELIBEXEC"; +#endif + case EILSEQ: + return "EILSEQ"; +#ifdef ERESTART + case ERESTART: + return "ERESTART"; +#endif +#ifdef ESTRPIPE + case ESTRPIPE: + return "ESTRPIPE"; +#endif +#ifdef EUSERS + case EUSERS: + return "EUSERS"; +#endif + case ENOTSOCK: + return "ENOTSOCK"; + case EDESTADDRREQ: + return "EDESTADDRREQ"; + case EMSGSIZE: + return "EMSGSIZE"; + case EPROTOTYPE: + return "EPROTOTYPE"; + case ENOPROTOOPT: + return "ENOPROTOOPT"; + case EPROTONOSUPPORT: + return "EPROTONOSUPPORT"; +#ifdef ESOCKTNOSUPPORT + case ESOCKTNOSUPPORT: + return "ESOCKTNOSUPPORT"; +#endif +#ifdef EOPNOTSUPP + case EOPNOTSUPP: + return "EOPNOTSUPP"; +#endif + case EPFNOSUPPORT: + return "EPFNOSUPPORT"; + case EAFNOSUPPORT: + return "EAFNOSUPPORT"; + case EADDRINUSE: + return "EADDRINUSE"; + case EADDRNOTAVAIL: + return "EADDRNOTAVAIL"; + case ENETDOWN: + return "ENETDOWN"; + case ENETUNREACH: + return "ENETUNREACH"; + case ENETRESET: + return "ENETRESET"; + case ECONNABORTED: + return "ECONNABORTED"; + case ECONNRESET: + return "ECONNRESET"; + case ENOBUFS: + return "ENOBUFS"; + case EISCONN: + return "EISCONN"; + case ENOTCONN: + return "ENOTCONN"; +#ifdef ESHUTDOWN + case ESHUTDOWN: + return "ESHUTDOWN"; +#endif +#ifdef ETOOMANYREFS + case ETOOMANYREFS: + return "ETOOMANYREFS"; +#endif + case ETIMEDOUT: + return "ETIMEDOUT"; + case ECONNREFUSED: + return "ECONNREFUSED"; +#ifdef EHOSTDOWN + case EHOSTDOWN: + return "EHOSTDOWN"; +#endif + case EHOSTUNREACH: + return "EHOSTUNREACH"; + case EALREADY: + return "EALREADY"; + case EINPROGRESS: + return "EINPROGRESS"; + case ESTALE: + return "ESTALE"; +#ifdef EUCLEAN + case EUCLEAN: + return "EUCLEAN"; +#endif +#ifdef ENOTNAM + case ENOTNAM: + return "ENOTNAM"; +#endif +#ifdef ENAVAIL + case ENAVAIL: + return "ENAVAIL"; +#endif +#ifdef EISNAM + case EISNAM: + return "EISNAM"; +#endif +#ifdef EREMOTEIO + case EREMOTEIO: + return "EREMOTEIO"; +#endif + case EDQUOT: + return "EDQUOT"; +#ifdef ENOMEDIUM + case ENOMEDIUM: + return "ENOMEDIUM"; +#endif +#ifdef EMEDIUMTYPE + case EMEDIUMTYPE: + return "EMEDIUMTYPE"; +#endif + case ECANCELED: + return "ECANCELED"; +#ifdef ENOKEY + case ENOKEY: + return "ENOKEY"; +#endif +#ifdef EKEYEXPIRED + case EKEYEXPIRED: + return "EKEYEXPIRED"; +#endif +#ifdef EKEYREVOKED + case EKEYREVOKED: + return "EKEYREVOKED"; +#endif +#ifdef EKEYREJECTED + case EKEYREJECTED: + return "EKEYREJECTED"; +#endif +#ifdef EOWNERDEAD + case EOWNERDEAD: + return "EOWNERDEAD"; +#endif +#ifdef ENOTRECOVERABLE + case ENOTRECOVERABLE: + return "ENOTRECOVERABLE"; +#endif +#ifdef ERFKILL + case ERFKILL: + return "ERFKILL"; +#endif +#ifdef EHWPOISON + case EHWPOISON: + return "EHWPOISON"; +#endif +#ifdef EPROCLIM + case EPROCLIM: + return "EPROCLIM"; +#endif +#ifdef EBADRPC + case EBADRPC: + return "EBADRPC"; +#endif +#ifdef ERPCMISMATCH + case ERPCMISMATCH: + return "ERPCMISMATCH"; +#endif +#ifdef EPROGUNAVAIL + case EPROGUNAVAIL: + return "EPROGUNAVAIL"; +#endif +#ifdef EPROGMISMATCH + case EPROGMISMATCH: + return "EPROGMISMATCH"; +#endif +#ifdef EPROCUNAVAIL + case EPROCUNAVAIL: + return "EPROCUNAVAIL"; +#endif +#ifdef EFTYPE + case EFTYPE: + return "EFTYPE"; +#endif +#ifdef EAUTH + case EAUTH: + return "EAUTH"; +#endif +#ifdef ENEEDAUTH + case ENEEDAUTH: + return "ENEEDAUTH"; +#endif +#ifdef EPWROFF + case EPWROFF: + return "EPWROFF"; +#endif +#ifdef EDEVERR + case EDEVERR: + return "EDEVERR"; +#endif +#ifdef EBADEXEC + case EBADEXEC: + return "EBADEXEC"; +#endif +#ifdef EBADARCH + case EBADARCH: + return "EBADARCH"; +#endif +#ifdef ESHLIBVERS + case ESHLIBVERS: + return "ESHLIBVERS"; +#endif +#ifdef EBADMACHO + case EBADMACHO: + return "EBADMACHO"; +#endif +#ifdef ENOATTR + case ENOATTR: + return "ENOATTR"; +#endif +#ifdef EQFULL + case EQFULL: + return "EQFULL"; +#endif + default: + char* str = strerror(nErrno); + return std::to_string(nErrno) + " (" + std::string(str) + ")"; + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |