]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
General code clean-up.
authorOliver Kurth <okurth@vmware.com>
Tue, 29 Jan 2019 22:03:18 +0000 (14:03 -0800)
committerOliver Kurth <okurth@vmware.com>
Tue, 29 Jan 2019 22:03:18 +0000 (14:03 -0800)
bora/lib/misc/posixPosix.c:
  Treat local variables "len" consistently as "size_t" type in
  Posix_Getmntent_r()

bora-vmsoft/apps/toolbox-cmd/toolboxcmd-shrink.c:
  Improve readability of error handling logic in ShrinkDoWipeAndShrink()
  and remove another line of dead code.

bora-vmsoft/lib/procMgr/procMgrPosix.c:
  Recent discussions about setting "errno" to ENOENT when either
  getpwuid_r() or getpwnam_r() return 0 (success) if there is no passwd
  entry for the user have vacillated.

  Since none of the current callers of the routines in procMgrPosix.c
  query the contents of "errno", the current consensus is to simply log
  a warning message along with reason for the failure.

open-vm-tools/lib/misc/posixPosix.c
open-vm-tools/lib/procMgr/procMgrPosix.c
open-vm-tools/toolbox/toolboxcmd-shrink.c

index 2c1c278e7b36ede2ba1febff9e6e6322a1cf7a73..7e0d5da5ece4a8f295240c82521b9806443afdd6 100644 (file)
@@ -2075,7 +2075,7 @@ Posix_Getmntent_r(FILE *fp,          // IN:
    n = 0;
 
    if (fsname) {
-      int len = strlen(fsname) + 1;
+      size_t len = strlen(fsname) + 1;
 
       if (n + len > size || n + len < n) {
          goto exit;
@@ -2085,7 +2085,7 @@ Posix_Getmntent_r(FILE *fp,          // IN:
    }
 
    if (dir != NULL) {
-      int len = strlen(dir) + 1;
+      size_t len = strlen(dir) + 1;
 
       if (n + len > size || n + len < n) {
          goto exit;
@@ -2095,7 +2095,7 @@ Posix_Getmntent_r(FILE *fp,          // IN:
    }
 
    if (type) {
-      int len = strlen(type) + 1;
+      size_t len = strlen(type) + 1;
 
       if (n + len > size || n + len < n) {
          goto exit;
@@ -2128,7 +2128,7 @@ exit:
    }
 
    return m;
-#endif // defined __ANDROID__
+#endif // NO_GETMNTENT_R
 }
 
 
index d07b5d3ffea7cc8580d3013eeb268748a130d1d4..267933e334c5429cbfe7e2168f173341f9e3fb38 100644 (file)
@@ -2205,9 +2205,8 @@ ProcMgr_ImpersonateUserStart(const char *user,  // IN: UTF-8 encoded user name
        * set the return pointer (ppw) if there's no entry for the user,
        * according to POSIX 1003.1-2003, so patch up the errno.
        */
-      if (error == 0) {
-         errno = ENOENT;
-      }
+      Warning("Failed to lookup user with uid: %" FMTUID ". Reason: %s\n", 0,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
       return FALSE;
    }
 
@@ -2220,17 +2219,16 @@ ProcMgr_ImpersonateUserStart(const char *user,  // IN: UTF-8 encoded user name
        return FALSE;
    }
 
-   error = getpwnam_r(userLocal, &pw, buffer, sizeof buffer, &ppw);
-
-   free(userLocal);
-
-   if (error != 0 || !ppw) {
-      if (error == 0) {
-         error = ENOENT;
-      }
+   if ((error = getpwnam_r(userLocal, &pw, buffer, sizeof buffer, &ppw)) != 0 ||
+       !ppw) {
+      Warning("Failed to lookup user name %s. Reason: %s\n", userLocal,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
+      free(userLocal);
       return FALSE;
    }
 
+   free(userLocal);
+
    // first change group
 #if defined(USERWORLD)
    ret = Id_SetREGid(ppw->pw_gid, ppw->pw_gid);
@@ -2306,9 +2304,8 @@ ProcMgr_ImpersonateUserStop(void)
 
    if ((error = getpwuid_r(0, &pw, buffer, sizeof buffer, &ppw)) != 0 ||
        !ppw) {
-      if (error == 0) {
-         error = ENOENT;
-      }
+      Warning("Failed to lookup user with uid: %" FMTUID ". Reason: %s\n", 0,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
       return FALSE;
    }
 
@@ -2432,9 +2429,8 @@ ProcMgr_GetImpersonatedUserInfo(char **userName,            // OUT
        * set the return pointer (ppw) if there's no entry for the user,
        * according to POSIX 1003.1-2003, so patch up the errno.
        */
-      if (error == 0) {
-         error = ENOENT;
-      }
+      Warning("Failed to lookup user with uid: %" FMTUID ". Reason: %s\n", uid,
+              error == 0 ? "entry not found" : Err_Errno2String(error));
       return FALSE;
    }
 
index b6896a3d9c01368896fe80e26526d68cb45448c6..8f6ea1f2e50d52586dbda84465ff3c0e0de6e3d3 100644 (file)
@@ -438,6 +438,7 @@ ShrinkDoWipeAndShrink(char *mountPoint,         // IN: mount point
          } else {
             ToolsCmd_PrintErr(SU_(error.message, "Error: %s\n"), err);
          }
+         /* progress < 100 will result in "rc" of EX_TEMPFAIL */
          break;
       }
 
@@ -459,14 +460,14 @@ ShrinkDoWipeAndShrink(char *mountPoint,         // IN: mount point
    }
 #endif
 
-   rc = EXIT_SUCCESS;
    g_print("\n");
-   if (progress >= 100 && performShrink) {
-      rc = ShrinkDiskSendRPC();
-   } else if (progress < 100) {
+   if (progress < 100) {
       rc = EX_TEMPFAIL;
+   } else if (performShrink) {
+      rc = ShrinkDiskSendRPC();
    } else {
-      g_debug("Shrinking skipped.\n");
+      rc = EXIT_SUCCESS;
+      g_debug("Shrink skipped.\n");
    }
 
    if (rc != EXIT_SUCCESS) {