From: Oliver Kurth Date: Fri, 7 Sep 2018 22:53:27 +0000 (-0700) Subject: Return proper vix error code when guest op VIX_COMMAND_DELETE_GUEST_DIRECTORY_EX... X-Git-Tag: stable-10.3.5~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5200ba3a770463e5c6a9e9d7e7a6a949857332ec;p=thirdparty%2Fopen-vm-tools.git Return proper vix error code when guest op VIX_COMMAND_DELETE_GUEST_DIRECTORY_EX fails. --- diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index 605324740..2d1154b38 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -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; } diff --git a/open-vm-tools/lib/include/err.h b/open-vm-tools/lib/include/err.h index b692db43e..064b76a2b 100644 --- a/open-vm-tools/lib/include/err.h +++ b/open-vm-tools/lib/include/err.h @@ -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 diff --git a/open-vm-tools/lib/include/posix.h b/open-vm-tools/lib/include/posix.h index 4a643f011..b5ae88394 100644 --- a/open-vm-tools/lib/include/posix.h +++ b/open-vm-tools/lib/include/posix.h @@ -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) /* diff --git a/open-vm-tools/lib/include/unicodeBase.h b/open-vm-tools/lib/include/unicodeBase.h index b79c6c858..4f5776e89 100644 --- a/open-vm-tools/lib/include/unicodeBase.h +++ b/open-vm-tools/lib/include/unicodeBase.h @@ -34,6 +34,7 @@ #include #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)