]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Ensure POSIX errno decode is done portably
authorVMware, Inc <>
Thu, 24 Feb 2011 22:42:10 +0000 (14:42 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 24 Feb 2011 22:42:10 +0000 (14:42 -0800)
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 <mvanzin@vmware.com>
open-vm-tools/lib/err/err.c
open-vm-tools/lib/file/fileIO.c
open-vm-tools/lib/file/fileLockPrimitive.c

index 99376c5d4d8beb86ab3d9562a6454b018ff4ee13..cb766e1d779e793ec756015e834cd2b041208192 100644 (file)
@@ -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
index 951e095bb2d20589aef835c29e5c78522510498c..f393cb67846a027f355d2cacf1bbeb3887f4daa2 100644 (file)
@@ -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;
       }
index c7e0988e941a101b3abb9dbe6b0a1c3031a1901d..41a8d5b8245c0ecee4e8efa1944f3fccc0f19e34 100644 (file)
@@ -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));
       }
    }