]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix the deployPkg status files when privateTmp is enabled
authorOliver Kurth <okurth@vmware.com>
Mon, 9 Sep 2019 18:23:49 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Mon, 9 Sep 2019 18:23:49 +0000 (11:23 -0700)
Currently, deployPkg status file path is hardcoded to /tmp.  When
privateTmp is enabled in the guest VM, /tmp is hidden from the rest
of the system and is wiped on reboot.  So need use different path to
save the status file.

This change is changing deployPkg status file path from /tmp to /var/log

open-vm-tools/libDeployPkg/linuxDeployment.c

index 1af08936ee5397801271073c3d56e29b9ae689dc..7615c9f8faf7dc91acb76e63a12a49510213a1a7 100644 (file)
@@ -81,8 +81,8 @@ VM_EMBED_VERSION(SYSIMAGE_VERSION_EXT_STR);
 #define IMC_DIR_PATH_PATTERN "/.vmware-imgcust-dXXXXXX"
 #endif
 
-#ifndef BASEFILENAME
-#define BASEFILENAME "/tmp/.vmware-deploy"
+#ifndef STATE_FILE_PATH_BASENAME
+#define STATE_FILE_PATH_BASENAME "/var/log/.vmware-deploy"
 #endif
 
 #ifndef CABCOMMANDLOG
@@ -319,7 +319,7 @@ SetCustomizationStatusInVmxEx(int customizationState,
                                 customizationState,
                                 errCode,
                                 msg);
-   free (msg);
+   free(msg);
 
    if (vmxResponse != NULL) {
       if (response != NULL) {
@@ -415,7 +415,7 @@ NoLogging(int level, const char* fmtstr, ...)
  *
  * SetDeployError
  *
- *    Sets the deployment error in a verbose style. Can be queried using
+ *    Set the deployment error in a verbose style. Can be queried using
  *    GetDeployError.
  *
  * @param   format   [in]  Format string to follow.
@@ -596,7 +596,7 @@ static void
 Init(void)
 {
    // Clean up if there is any deployment locks/status before
-   sLog(log_info, "Cleaning old state file from tmp directory.\n");
+   sLog(log_info, "Cleaning old state files.\n");
    UnTouch(INPROGRESS);
    UnTouch(DONE);
    UnTouch(ERRORED);
@@ -695,32 +695,33 @@ GetPackageInfo(const char* packageName,
  *
  **/
 static DeployPkgStatus
-Touch(const char*  state)
+Touch(const char* state)
 {
-   int fileNameSize = strlen(BASEFILENAME) + 1 + strlen(state) + 1;
+   int fileNameSize = strlen(STATE_FILE_PATH_BASENAME) + 1 /* For '.' */ +
+                      strlen(state) + 1;
    char* fileName = malloc(fileNameSize);
    int fd;
 
    sLog(log_info, "ENTER STATE '%s'.\n", state);
    if (!fileName) {
-      SetDeployError("Error allocatin memory.");
+      SetDeployError("Error allocating memory.");
       return DEPLOYPKG_STATUS_ERROR;
    }
 
-   strcpy(fileName, BASEFILENAME);
-   Str_Strcat(fileName, ".", fileNameSize);
-   Str_Strcat(fileName, state, fileNameSize);
+   Str_Snprintf(fileName, fileNameSize, "%s.%s", STATE_FILE_PATH_BASENAME,
+                state);
 
    fd = open(fileName, O_WRONLY|O_CREAT|O_EXCL, 0644);
 
    if (fd < 0) {
-      SetDeployError("Error creating lock file '%s'.(%s)", fileName, strerror(errno));
-      free (fileName);
+      SetDeployError("Error creating lock file '%s'.(%s)", fileName,
+                     strerror(errno));
+      free(fileName);
       return DEPLOYPKG_STATUS_ERROR;
    }
 
    close(fd);
-   free (fileName);
+   free(fileName);
 
    return DEPLOYPKG_STATUS_SUCCESS;
 }
@@ -739,7 +740,8 @@ Touch(const char*  state)
 static DeployPkgStatus
 UnTouch(const char* state)
 {
-   int fileNameSize = strlen(BASEFILENAME) + 1 + strlen(state) + 1;
+   int fileNameSize = strlen(STATE_FILE_PATH_BASENAME) + 1 /* For '.' */ +
+                      strlen(state) + 1;
    char* fileName = malloc(fileNameSize);
    int result;
 
@@ -749,19 +751,19 @@ UnTouch(const char* state)
       return DEPLOYPKG_STATUS_ERROR;
    }
 
-   strcpy(fileName, BASEFILENAME);
-   Str_Strcat(fileName, ".", fileNameSize);
-   Str_Strcat(fileName, state, fileNameSize);
+   Str_Snprintf(fileName, fileNameSize, "%s.%s", STATE_FILE_PATH_BASENAME,
+                state);
 
    result = remove(fileName);
 
    if (result < 0) {
-      SetDeployError("Error removing lock '%s'.(%s)", fileName, strerror(errno));
-      free (fileName);
+      SetDeployError("Error removing lock '%s'.(%s)", fileName,
+                     strerror(errno));
+      free(fileName);
       return DEPLOYPKG_STATUS_ERROR;
    }
 
-   free (fileName);
+   free(fileName);
    return DEPLOYPKG_STATUS_SUCCESS;
 }
 
@@ -1386,7 +1388,7 @@ Deploy(const char* packageName)
       sLog(log_warning, "Error while cleaning up imc directory '%s'. (%s)\n",
            imcDirPath, strerror (errno));
    }
-   free (cleanupCommand);
+   free(cleanupCommand);
    free(imcDirPath);
 
    if (flags & VMWAREDEPLOYPKG_HEADER_FLAGS_SKIP_REBOOT) {