Kaydet (Commit) 22a2ed83 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Introduce UnixErrnoString() and use it in sal/osl/unx

The UnixErrnoString() function returns the symbolic name of an errno
value, like "ENOENT". For now this is local to sal/osl/unx.

If it can't figure out the symbolic name, it returns it as a number
followed by the cleartext description (as from strerror()) in
parentheses.

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. The symbolic names
of errno values are (or should be) instantly recognizable as such,
they all start with E and are in UPPERCASE.

strerror() can be localised although in LibreOffice it apparently
isn't as there allegedly aren't setlocale() calls. But, anyway, the
error strings might be less familiar to a developer than the symbolc
errno names that one uses when coding.

When encountering an unfamiliar error string the developer might want
to add special handling for that error case in the code. They would
need a reverse mapping from error string to errno value, by manually
searching <errno.h>, looking at the comments there, hoping the match
what strerror() produces, to find the corresponding symbolic errno
value.

Change-Id: Idc11595d528e8432a32bf474e6791f4ea7262a1e
Reviewed-on: https://gerrit.libreoffice.org/61931
Tested-by: Jenkins
Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
üst 9a373521
......@@ -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") );
......
......@@ -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
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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 )
......
......@@ -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
{
......
......@@ -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);
}
......
......@@ -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 */
......
/* -*- 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: */
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment