]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Return proper vix error code when guest op VIX_COMMAND_DELETE_GUEST_DIRECTORY_EX...
authorOliver Kurth <okurth@vmware.com>
Fri, 7 Sep 2018 22:53:27 +0000 (15:53 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 7 Sep 2018 22:53:27 +0000 (15:53 -0700)
open-vm-tools/lib/file/file.c
open-vm-tools/lib/include/err.h
open-vm-tools/lib/include/posix.h
open-vm-tools/lib/include/unicodeBase.h

index 60532474057c6c68cc420f4be3673ce690076746..2d1154b38d844fa02bb48d38522658bb957b0520 100644 (file)
@@ -1863,7 +1863,7 @@ FileDeleteDirectoryTree(const char *pathName,  // IN: directory to delete
    char *base;
 
    char **fileList = NULL;
-   Bool sawFileError = FALSE;
+   Err_Number fileError = 0;
 
    if (Posix_EuidAccess(pathName, F_OK) != 0) {
       /*
@@ -1909,7 +1909,7 @@ FileDeleteDirectoryTree(const char *pathName,  // IN: directory to delete
          case S_IFDIR:
             /* Directory, recurse */
             if (!FileDeleteDirectoryTree(curPath, FALSE)) {
-               sawFileError = TRUE;
+               fileError = Err_Errno();
             }
             break;
 
@@ -1917,7 +1917,7 @@ FileDeleteDirectoryTree(const char *pathName,  // IN: directory to delete
          case S_IFLNK:
             /* Delete symlink, not what it points to */
             if (FileDeletion(curPath, FALSE) != 0) {
-               sawFileError = TRUE;
+               fileError = Err_Errno();
             }
             break;
 #endif
@@ -1927,19 +1927,21 @@ FileDeleteDirectoryTree(const char *pathName,  // IN: directory to delete
 #if defined(_WIN32)
                if (File_SetFilePermissions(curPath, S_IWUSR)) {
                   if (FileDeletion(curPath, FALSE) != 0) {
-                     sawFileError = TRUE;
+                     fileError = Err_Errno();
                   }
                } else {
-                  sawFileError = TRUE;
+                  fileError = Err_Errno();
                }
 #else
-               sawFileError = TRUE;
+               fileError = Err_Errno();
 #endif
             }
             break;
          }
       } else {
-         sawFileError = TRUE;
+         fileError = Err_Errno();
+         Log(LGPFX" %s: Lstat of '%s' failed, errno = %d\n",
+             __FUNCTION__, curPath, errno);
       }
 
       Posix_Free(curPath);
@@ -1952,14 +1954,16 @@ FileDeleteDirectoryTree(const char *pathName,  // IN: directory to delete
        * Call File_DeleteEmptyDirectory() only if there is no prior error
        * while deleting the children.
        */
-      if (!sawFileError && !File_DeleteEmptyDirectory(pathName)) {
-         sawFileError = TRUE;
+      if (fileError == 0 && !File_DeleteEmptyDirectory(pathName)) {
+         fileError = Err_Errno();
       }
    }
 
    Util_FreeStringList(fileList, numFiles);
 
-   return !sawFileError;
+   Err_SetErrno(fileError);
+
+   return fileError == 0;
 }
 
 
index b692db43e1a2e777befc52ee2e19b1824f2b2ed0..064b76a2b4c781d80a0c6ced7b70e8572930cb95 100644 (file)
@@ -137,6 +137,8 @@ char *Err_SanitizeMessage(const char *msg);
    } while (0)
 #endif
 
+#define WITH_ERRNO_FREE(p) WITH_ERRNO(__errNum__, free((void *)p))
+
 #if defined(__cplusplus)
 }  // extern "C"
 #endif
index 4a643f0113902377ea709be93eceafd9ae530521..b5ae883947a0d3df97fe68e171a3b226a4a113c9 100644 (file)
@@ -35,6 +35,7 @@
 #include "unicodeTypes.h"
 #include "unicodeBase.h"
 #include "codeset.h"
+#include "err.h"
 
 #if defined(__cplusplus)
 extern "C" {
@@ -125,14 +126,7 @@ char *Posix_MkTemp(const char *pathName);
  *-----------------------------------------------------------------------------
  */
 
-static INLINE void
-Posix_Free(void *p)  // IN
-{
-   int err = errno;
-   free(p);
-   errno = err;
-}
-
+#define Posix_Free(p) WITH_ERRNO_FREE(p)
 
 #if !defined(_WIN32)
 /*
index b79c6c858f665c7678646f186b97543268bb7323..4f5776e89c1b320d93ac31fe40002c596b5f5697 100644 (file)
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include "util.h"
 #include "unicodeTypes.h"
+#include "err.h"
 
 #if defined(__cplusplus)
 extern "C" {
@@ -348,11 +349,7 @@ const char *Unicode_GetStatic(const char *asciiBytes,
  */
 #if defined(_WIN32)
    #define UNICODE_GET_UTF16(s)     Unicode_GetAllocUTF16(s)
-   #define UNICODE_RELEASE_UTF16(s) do { \
-         int err = errno; \
-         free((utf16_t *)s); \
-         errno = err; \
-      } while (0)
+   #define UNICODE_RELEASE_UTF16(s) WITH_ERRNO_FREE(s)
 #endif
 
 #if defined(__cplusplus)