Blame SOURCES/0002-Update-cloud-init-handling.patch

23fda9
From 83724a3f0c7ae5bc6586d5fd52a5b432fdd70fab Mon Sep 17 00:00:00 2001
23fda9
From: Miroslav Rezanina <mrezanin@redhat.com>
23fda9
Date: Tue, 16 Oct 2018 07:20:56 +0200
23fda9
Subject: Update cloud-init handling
23fda9
23fda9
This update of cloud-init changes for 10.3.0.
23fda9
---
23fda9
 open-vm-tools/libDeployPkg/linuxDeployment.c       | 57 ++++++++++++++--------
23fda9
 .../libDeployPkg/linuxDeploymentUtilities.c        |  3 +-
23fda9
 2 files changed, 38 insertions(+), 22 deletions(-)
23fda9
23fda9
diff --git a/libDeployPkg/linuxDeployment.c b/libDeployPkg/linuxDeployment.c
23fda9
index 996f184..34c8b95 100644
23fda9
--- a/libDeployPkg/linuxDeployment.c
23fda9
+++ b/libDeployPkg/linuxDeployment.c
23fda9
@@ -139,7 +139,7 @@ static bool CopyFileToDirectory(const char* srcPath, const char* destPath,
23fda9
                                 const char* fileName);
23fda9
 static DeployPkgStatus Deploy(const char* pkgName);
23fda9
 static char** GetFormattedCommandLine(const char* command);
23fda9
-int ForkExecAndWaitCommand(const char* command);
23fda9
+int ForkExecAndWaitCommand(const char* command, bool ignoreStdErr);
23fda9
 static void SetDeployError(const char* format, ...);
23fda9
 static const char* GetDeployError(void);
23fda9
 static void NoLogging(int level, const char* fmtstr, ...);
23fda9
@@ -920,7 +920,7 @@ CloudInitSetup(const char *tmpDirPath)
23fda9
             "/bin/mkdir -p %s", cloudInitTmpDirPath);
23fda9
    command[sizeof(command) - 1] = '\0';
23fda9
 
23fda9
-   forkExecResult = ForkExecAndWaitCommand(command);
23fda9
+   forkExecResult = ForkExecAndWaitCommand(command, false);
23fda9
    if (forkExecResult != 0) {
23fda9
       SetDeployError("Error creating %s dir: %s",
23fda9
                      cloudInitTmpDirPath,
23fda9
@@ -937,7 +937,7 @@ CloudInitSetup(const char *tmpDirPath)
23fda9
             "/usr/bin/test -f %s/nics.txt", tmpDirPath);
23fda9
    command[sizeof(command) - 1] = '\0';
23fda9
 
23fda9
-   forkExecResult = ForkExecAndWaitCommand(command);
23fda9
+   forkExecResult = ForkExecAndWaitCommand(command, false);
23fda9
 
23fda9
    /*
23fda9
     * /usr/bin/test -f returns 0 if the file exists
23fda9
@@ -946,7 +946,7 @@ CloudInitSetup(const char *tmpDirPath)
23fda9
     */
23fda9
    if (forkExecResult == 0) {
23fda9
       sLog(log_info, "nics.txt file exists. Copying..");
23fda9
-      if(!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "nics.txt")) {
23fda9
+      if (!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "nics.txt")) {
23fda9
          goto done;
23fda9
        }
23fda9
    }
23fda9
@@ -973,7 +973,7 @@ CloudInitSetup(const char *tmpDirPath)
23fda9
    }
23fda9
 
23fda9
    sLog(log_info, "Copying main configuration file cust.cfg");
23fda9
-   if(!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "cust.cfg")) {
23fda9
+   if (!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "cust.cfg")) {
23fda9
       goto done;
23fda9
    }
23fda9
 
23fda9
@@ -992,7 +992,7 @@ done:
23fda9
                   "/bin/rm -rf %s",
23fda9
                   cloudInitTmpDirPath);
23fda9
          command[sizeof(command) - 1] = '\0';
23fda9
-         ForkExecAndWaitCommand(command);
23fda9
+         ForkExecAndWaitCommand(command, false);
23fda9
       }
23fda9
       sLog(log_error, "Setting generic error status in vmx. \n");
23fda9
       SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_RUNNING,
23fda9
@@ -1016,7 +1016,7 @@ CopyFileToDirectory(const char* srcPath, const char* destPath,
23fda9
    snprintf(command, sizeof(command), "/bin/cp %s/%s %s/%s.tmp", srcPath,
23fda9
             fileName, destPath, fileName);
23fda9
    command[sizeof(command) - 1] = '\0';
23fda9
-   forkExecResult = ForkExecAndWaitCommand(command);
23fda9
+   forkExecResult = ForkExecAndWaitCommand(command, false);
23fda9
    if (forkExecResult != 0) {
23fda9
       SetDeployError("Error while copying file %s: %s", fileName,
23fda9
                      strerror(errno));
23fda9
@@ -1026,7 +1026,7 @@ CopyFileToDirectory(const char* srcPath, const char* destPath,
23fda9
             fileName, destPath, fileName);
23fda9
    command[sizeof(command) - 1] = '\0';
23fda9
 
23fda9
-   forkExecResult = ForkExecAndWaitCommand(command);
23fda9
+   forkExecResult = ForkExecAndWaitCommand(command, false);
23fda9
    if (forkExecResult != 0) {
23fda9
       SetDeployError("Error while renaming temp file %s: %s", fileName,
23fda9
                      strerror(errno));
23fda9
@@ -1090,7 +1090,7 @@ UseCloudInitWorkflow(const char* dirPath)
23fda9
       sLog(log_info, "cust.cfg is found in '%s' directory.", dirPath);
23fda9
    }
23fda9
 
23fda9
-   forkExecResult = ForkExecAndWaitCommand(cloudInitCommand);
23fda9
+   forkExecResult = ForkExecAndWaitCommand(cloudInitCommand, true);
23fda9
    if (forkExecResult != 0) {
23fda9
       sLog(log_info, "cloud-init is not installed");
23fda9
       free(cfgFullPath);
23fda9
@@ -1194,7 +1194,7 @@ Deploy(const char* packageName)
23fda9
       deployPkgStatus = CloudInitSetup(tmpDirPath);
23fda9
    } else {
23fda9
       sLog(log_info, "Executing traditional GOSC workflow");
23fda9
-      deploymentResult = ForkExecAndWaitCommand(command);
23fda9
+      deploymentResult = ForkExecAndWaitCommand(command, false);
23fda9
       free(command);
23fda9
 
23fda9
       if (deploymentResult != CUST_SUCCESS) {
23fda9
@@ -1260,7 +1260,7 @@ Deploy(const char* packageName)
23fda9
    strcat(cleanupCommand, tmpDirPath);
23fda9
 
23fda9
    sLog(log_info, "Launching cleanup. \n");
23fda9
-   if (ForkExecAndWaitCommand(cleanupCommand) != 0) {
23fda9
+   if (ForkExecAndWaitCommand(cleanupCommand, false) != 0) {
23fda9
       sLog(log_warning, "Error while clean up tmp directory %s: (%s)",
23fda9
            tmpDirPath, strerror (errno));
23fda9
    }
23fda9
@@ -1289,7 +1289,7 @@ Deploy(const char* packageName)
23fda9
          int rebootComandResult = 0;
23fda9
          do {
23fda9
             sLog(log_info, "Rebooting\n");
23fda9
-            rebootComandResult = ForkExecAndWaitCommand("/sbin/telinit 6");
23fda9
+            rebootComandResult = ForkExecAndWaitCommand("/sbin/telinit 6", false);
23fda9
             sleep(1);
23fda9
          } while (rebootComandResult == 0);
23fda9
          sLog(log_error, "telinit returned error %d\n", rebootComandResult);
23fda9
@@ -1499,12 +1499,13 @@ GetFormattedCommandLine(const char* command)
23fda9
  * Fork off the command and wait for it to finish. Classical Linux/Unix
23fda9
  * fork-and-exec.
23fda9
  *
23fda9
- * @param   [IN]  command  Command to execute
23fda9
+ * @param   [IN]  command       Command to execute
23fda9
+ * @param   [IN]  ignoreStdErr  If we ignore stderr when cmd's return code is 0
23fda9
  * @return  Return code from the process (or -1)
23fda9
  *
23fda9
  **/
23fda9
 int
23fda9
-ForkExecAndWaitCommand(const char* command)
23fda9
+ForkExecAndWaitCommand(const char* command, bool ignoreStdErr)
23fda9
 {
23fda9
    ProcessHandle hp;
23fda9
    int retval;
23fda9
@@ -1522,14 +1523,30 @@ ForkExecAndWaitCommand(const char* command)
23fda9
 
23fda9
    Process_RunToComplete(hp, 100);
23fda9
    sLog(log_info, "Customization command output: %s\n", Process_GetStdout(hp));
23fda9
-
23fda9
-   if(Process_GetExitCode(hp) == 0 && strlen(Process_GetStderr(hp)) > 0) {
23fda9
-      // Assume command failed if it wrote to stderr, even if exitCode is 0
23fda9
-      sLog(log_error, "Customization command failed: %s\n", Process_GetStderr(hp));
23fda9
-      retval = -1;
23fda9
+   retval = Process_GetExitCode(hp);
23fda9
+
23fda9
+   if (retval == 0) {
23fda9
+      if (strlen(Process_GetStderr(hp)) > 0) {
23fda9
+         if (!ignoreStdErr) {
23fda9
+            // Assume command failed if it wrote to stderr, even if exitCode is 0
23fda9
+            sLog(log_error,
23fda9
+                 "Customization command failed with stderr: %s\n",
23fda9
+                 Process_GetStderr(hp));
23fda9
+            retval = -1;
23fda9
+         } else {
23fda9
+            // If we choose to ignore stderr, we do not return -1 when return
23fda9
+            // code is 0. e.g, PR2148977, "cloud-init -v" will return 0
23fda9
+            // even there is output in stderr
23fda9
+            sLog(log_info, "Ignoring stderr output: %s\n", Process_GetStderr(hp));
23fda9
+         }
23fda9
+      }
23fda9
    } else {
23fda9
-      retval = Process_GetExitCode(hp);
23fda9
+      sLog(log_error,
23fda9
+           "Customization command failed with exitcode: %d, stderr: %s\n",
23fda9
+           retval,
23fda9
+           Process_GetStderr(hp));
23fda9
    }
23fda9
+
23fda9
    Process_Destroy(hp);
23fda9
    return retval;
23fda9
 }
23fda9
diff --git a/libDeployPkg/linuxDeploymentUtilities.c b/libDeployPkg/linuxDeploymentUtilities.c
23fda9
index 83f942d..93e1b0a 100644
23fda9
--- a/libDeployPkg/linuxDeploymentUtilities.c
23fda9
+++ b/libDeployPkg/linuxDeploymentUtilities.c
23fda9
@@ -1,5 +1,5 @@
23fda9
 /*********************************************************
23fda9
- * Copyright (C) 2016-2017 VMware, Inc. All rights reserved.
23fda9
+ * Copyright (C) 2016-2018 VMware, Inc. All rights reserved.
23fda9
  *
23fda9
  * This program is free software; you can redistribute it and/or modify it
23fda9
  * under the terms of the GNU Lesser General Public License as published
23fda9
@@ -24,7 +24,6 @@
23fda9
 #include <regex.h>
23fda9
 #include "linuxDeploymentUtilities.h"
23fda9
 
23fda9
-extern int ForkExecAndWaitCommand(const char* command);
23fda9
 extern LogFunction sLog;
23fda9
 
23fda9
 /**
23fda9
-- 
23fda9
1.8.3.1
23fda9