From: VMware, Inc <> Date: Thu, 24 Feb 2011 22:42:10 +0000 (-0800) Subject: Ensure POSIX errno decode is done portably X-Git-Tag: 2011.02.23-368700~29 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f1c0f394e69ac7faaa89dfbf50c4adde96820be;p=thirdparty%2Fopen-vm-tools.git Ensure POSIX errno decode is done portably In cross platform code we must use POSIX strerror to ensure that a POSIX errno value is translated to a string portably. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/err/err.c b/open-vm-tools/lib/err/err.c index 99376c5d4..cb766e1d7 100644 --- a/open-vm-tools/lib/err/err.c +++ b/open-vm-tools/lib/err/err.c @@ -74,6 +74,8 @@ Atomic_Ptr errStrTable; * Err_ErrString -- * * Returns a string that corresponds to the last error message. + * The error number used is that which is native to the platform, + * errno on POSIXen and GetLastError on Windows. * * Results: * Error message string. @@ -98,6 +100,8 @@ Err_ErrString(void) * Err_Errno2String -- * * Return a string that corresponds to the passed error number. + * The error number used is that which is native to the platform, + * errno on POSIXen and GetLastError on Windows. * * The string is in English in UTF-8, has indefinite lifetime, * and need not be freed. @@ -203,6 +207,8 @@ Err_Errno2String(Err_Number errorNumber) // IN * Err_String2Errno -- * * Return an error number that corresponds to the passed string. + * The error number used is that which is native to the platform, + * errno on POSIXen and GetLastError on Windows. * * To be recognized, the string must be one previously returned * by Err_Errno2String. Any other string (even a copy of diff --git a/open-vm-tools/lib/file/fileIO.c b/open-vm-tools/lib/file/fileIO.c index 951e095bb..f393cb678 100644 --- a/open-vm-tools/lib/file/fileIO.c +++ b/open-vm-tools/lib/file/fileIO.c @@ -269,7 +269,7 @@ FileIO_Lock(FileIODescriptor *file, // IN/OUT: /* Describe the lock not acquired situation in detail */ Warning(LGPFX" %s on '%s' failed: %s\n", __FUNCTION__, UTF8(file->fileName), - (err == 0) ? "Lock timed out" : Err_Errno2String(err)); + (err == 0) ? "Lock timed out" : strerror(err)); /* Return a serious failure status if the locking code did */ switch (err) { @@ -331,7 +331,7 @@ FileIO_Unlock(FileIODescriptor *file) // IN/OUT: if (err != 0) { Warning(LGPFX" %s on '%s' failed: %s\n", - __FUNCTION__, UTF8(file->fileName), Err_Errno2String(err)); + __FUNCTION__, UTF8(file->fileName), strerror(err)); ret = FILEIO_ERROR; } diff --git a/open-vm-tools/lib/file/fileLockPrimitive.c b/open-vm-tools/lib/file/fileLockPrimitive.c index c7e0988e9..41a8d5b82 100644 --- a/open-vm-tools/lib/file/fileLockPrimitive.c +++ b/open-vm-tools/lib/file/fileLockPrimitive.c @@ -185,7 +185,7 @@ RemoveLockingFile(ConstUnicode lockDir, // IN: err = 0; } else { Warning(LGPFX" %s of '%s' failed: %s\n", __FUNCTION__, - UTF8(path), Err_Errno2String(err)); + UTF8(path), strerror(err)); } } @@ -318,7 +318,7 @@ FileLockMemberValues(ConstUnicode lockDir, // IN: if (err != ENOENT) { Warning(LGPFX" %s open failure on '%s': %s\n", __FUNCTION__, - UTF8(path), Err_Errno2String(err)); + UTF8(path), strerror(err)); } goto bail; @@ -337,7 +337,7 @@ FileLockMemberValues(ConstUnicode lockDir, // IN: if (err != ENOENT) { Warning(LGPFX" %s file size failure on '%s': %s\n", __FUNCTION__, - UTF8(path), Err_Errno2String(err)); + UTF8(path), strerror(err)); } FileLockCloseFile(handle); @@ -362,7 +362,7 @@ FileLockMemberValues(ConstUnicode lockDir, // IN: if (err != 0) { Warning(LGPFX" %s read failure on '%s': %s\n", - __FUNCTION__, UTF8(path), Err_Errno2String(err)); + __FUNCTION__, UTF8(path), strerror(err)); goto bail; } @@ -977,7 +977,7 @@ FileUnlockIntrinsic(FileLockToken *tokenPtr) // IN: if (err && vmx86_debug) { Log(LGPFX" %s failed for '%s': %s\n", __FUNCTION__, - UTF8(tokenPtr->lockFilePath), Err_Errno2String(err)); + UTF8(tokenPtr->lockFilePath), strerror(err)); } /* @@ -1253,13 +1253,13 @@ CreateEntryDirectory(ConstUnicode lockDir, // IN: if ((err != 0) && (err != EEXIST)) { Warning(LGPFX" %s creation failure on '%s': %s\n", - __FUNCTION__, UTF8(lockDir), Err_Errno2String(err)); + __FUNCTION__, UTF8(lockDir), strerror(err)); break; } } else { Warning(LGPFX" %s stat failure on '%s': %s\n", - __FUNCTION__, UTF8(lockDir), Err_Errno2String(err)); + __FUNCTION__, UTF8(lockDir), strerror(err)); break; } @@ -1303,7 +1303,7 @@ CreateEntryDirectory(ConstUnicode lockDir, // IN: if (vmx86_debug) { Log(LGPFX" %s stat failure on '%s': %s\n", - __FUNCTION__, UTF8(*memberFilePath), Err_Errno2String(err)); + __FUNCTION__, UTF8(*memberFilePath), strerror(err)); } } @@ -1312,8 +1312,7 @@ CreateEntryDirectory(ConstUnicode lockDir, // IN: if ((err != EEXIST) && // Another process/thread created it... (err != ENOENT)) { // lockDir is gone... Warning(LGPFX" %s creation failure on '%s': %s\n", - __FUNCTION__, UTF8(*entryDirectory), - Err_Errno2String(err)); + __FUNCTION__, UTF8(*entryDirectory), strerror(err)); break; } @@ -1401,7 +1400,7 @@ CreateMemberFile(FILELOCK_FILE_HANDLE entryHandle, // IN: if (err != 0) { Warning(LGPFX" %s write of '%s' failed: %s\n", __FUNCTION__, - UTF8(entryFilePath), Err_Errno2String(err)); + UTF8(entryFilePath), strerror(err)); FileLockCloseFile(entryHandle); @@ -1412,7 +1411,7 @@ CreateMemberFile(FILELOCK_FILE_HANDLE entryHandle, // IN: if (err != 0) { Warning(LGPFX" %s close of '%s' failed: %s\n", __FUNCTION__, - UTF8(entryFilePath), Err_Errno2String(err)); + UTF8(entryFilePath), strerror(err)); return err; } @@ -1429,16 +1428,16 @@ CreateMemberFile(FILELOCK_FILE_HANDLE entryHandle, // IN: if (err != 0) { Warning(LGPFX" %s FileRename of '%s' to '%s' failed: %s\n", __FUNCTION__, UTF8(entryFilePath), UTF8(memberFilePath), - Err_Errno2String(err)); + strerror(err)); if (vmx86_debug) { Log(LGPFX" %s FileLockFileType() of '%s': %s\n", __FUNCTION__, UTF8(entryFilePath), - Err_Errno2String(FileAttributesRobust(entryFilePath, NULL))); + strerror(FileAttributesRobust(entryFilePath, NULL))); Log(LGPFX" %s FileLockFileType() of '%s': %s\n", __FUNCTION__, UTF8(memberFilePath), - Err_Errno2String(FileAttributesRobust(memberFilePath, NULL))); + strerror(FileAttributesRobust(memberFilePath, NULL))); } return err; @@ -1833,7 +1832,7 @@ FileLockHackVMX(ConstUnicode pathName) // IN: } else { if (vmx86_debug) { Warning(LGPFX" %s clean-up failure for '%s': %s\n", - __FUNCTION__, UTF8(pathName), Err_Errno2String(err)); + __FUNCTION__, UTF8(pathName), strerror(err)); } }