const char* fileName);
static DeployPkgStatus Deploy(const char* pkgName);
static char** GetFormattedCommandLine(const char* command);
-int ForkExecAndWaitCommand(const char* command);
+int ForkExecAndWaitCommand(const char* command, bool ignoreStdErr);
static void SetDeployError(const char* format, ...);
static const char* GetDeployError(void);
static void NoLogging(int level, const char* fmtstr, ...);
va_start(args, fmtstr);
vsprintf(tmp, fmtstr, args);
+ va_end(args);
sLog(log_error, "Panic callback invoked: %s\n", tmp);
va_start(args, fmtstr);
vsprintf(tmp, fmtstr, args);
+ va_end(args);
sLog(log_debug, "Debug callback invoked: %s\n", tmp);
if (tmp) {
va_start(args, format);
vsprintf(tmp, format, args);
+ va_end(args);
}
if (gDeployError) {
"/bin/mkdir -p %s", cloudInitTmpDirPath);
command[sizeof(command) - 1] = '\0';
- forkExecResult = ForkExecAndWaitCommand(command);
+ forkExecResult = ForkExecAndWaitCommand(command, false);
if (forkExecResult != 0) {
SetDeployError("Error creating %s dir: %s",
cloudInitTmpDirPath,
"/usr/bin/test -f %s/nics.txt", tmpDirPath);
command[sizeof(command) - 1] = '\0';
- forkExecResult = ForkExecAndWaitCommand(command);
+ forkExecResult = ForkExecAndWaitCommand(command, false);
/*
* /usr/bin/test -f returns 0 if the file exists
*/
if (forkExecResult == 0) {
sLog(log_info, "nics.txt file exists. Copying..");
- if(!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "nics.txt")) {
+ if (!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "nics.txt")) {
goto done;
}
}
}
sLog(log_info, "Copying main configuration file cust.cfg");
- if(!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "cust.cfg")) {
+ if (!CopyFileToDirectory(tmpDirPath, cloudInitTmpDirPath, "cust.cfg")) {
goto done;
}
"/bin/rm -rf %s",
cloudInitTmpDirPath);
command[sizeof(command) - 1] = '\0';
- ForkExecAndWaitCommand(command);
+ ForkExecAndWaitCommand(command, false);
}
sLog(log_error, "Setting generic error status in vmx. \n");
SetCustomizationStatusInVmx(TOOLSDEPLOYPKG_RUNNING,
snprintf(command, sizeof(command), "/bin/cp %s/%s %s/%s.tmp", srcPath,
fileName, destPath, fileName);
command[sizeof(command) - 1] = '\0';
- forkExecResult = ForkExecAndWaitCommand(command);
+ forkExecResult = ForkExecAndWaitCommand(command, false);
if (forkExecResult != 0) {
SetDeployError("Error while copying file %s: %s", fileName,
strerror(errno));
fileName, destPath, fileName);
command[sizeof(command) - 1] = '\0';
- forkExecResult = ForkExecAndWaitCommand(command);
+ forkExecResult = ForkExecAndWaitCommand(command, false);
if (forkExecResult != 0) {
SetDeployError("Error while renaming temp file %s: %s", fileName,
strerror(errno));
sLog(log_info, "cust.cfg is found in '%s' directory.", dirPath);
}
- forkExecResult = ForkExecAndWaitCommand(cloudInitCommand);
+ forkExecResult = ForkExecAndWaitCommand(cloudInitCommand, true);
if (forkExecResult != 0) {
sLog(log_info, "cloud-init is not installed");
free(cfgFullPath);
deployPkgStatus = CloudInitSetup(tmpDirPath);
} else {
sLog(log_info, "Executing traditional GOSC workflow");
- deploymentResult = ForkExecAndWaitCommand(command);
+ deploymentResult = ForkExecAndWaitCommand(command, false);
free(command);
if (deploymentResult != CUST_SUCCESS) {
strcat(cleanupCommand, tmpDirPath);
sLog(log_info, "Launching cleanup. \n");
- if (ForkExecAndWaitCommand(cleanupCommand) != 0) {
+ if (ForkExecAndWaitCommand(cleanupCommand, false) != 0) {
sLog(log_warning, "Error while clean up tmp directory %s: (%s)",
tmpDirPath, strerror (errno));
}
int rebootComandResult = 0;
do {
sLog(log_info, "Rebooting\n");
- rebootComandResult = ForkExecAndWaitCommand("/sbin/telinit 6");
+ rebootComandResult = ForkExecAndWaitCommand("/sbin/telinit 6", false);
sleep(1);
} while (rebootComandResult == 0);
sLog(log_error, "telinit returned error %d\n", rebootComandResult);
* Fork off the command and wait for it to finish. Classical Linux/Unix
* fork-and-exec.
*
- * @param [IN] command Command to execute
+ * @param [IN] command Command to execute
+ * @param [IN] ignoreStdErr If we ignore stderr when cmd's return code is 0
* @return Return code from the process (or -1)
*
**/
int
-ForkExecAndWaitCommand(const char* command)
+ForkExecAndWaitCommand(const char* command, bool ignoreStdErr)
{
ProcessHandle hp;
int retval;
Process_RunToComplete(hp, 100);
sLog(log_info, "Customization command output: %s\n", Process_GetStdout(hp));
-
- if(Process_GetExitCode(hp) == 0 && strlen(Process_GetStderr(hp)) > 0) {
- // Assume command failed if it wrote to stderr, even if exitCode is 0
- sLog(log_error, "Customization command failed: %s\n", Process_GetStderr(hp));
- retval = -1;
+ retval = Process_GetExitCode(hp);
+
+ if (retval == 0) {
+ if (strlen(Process_GetStderr(hp)) > 0) {
+ if (!ignoreStdErr) {
+ // Assume command failed if it wrote to stderr, even if exitCode is 0
+ sLog(log_error,
+ "Customization command failed with stderr: %s\n",
+ Process_GetStderr(hp));
+ retval = -1;
+ } else {
+ // If we choose to ignore stderr, we do not return -1 when return
+ // code is 0. e.g, PR2148977, "cloud-init -v" will return 0
+ // even there is output in stderr
+ sLog(log_info, "Ignoring stderr output: %s\n", Process_GetStderr(hp));
+ }
+ }
} else {
- retval = Process_GetExitCode(hp);
+ sLog(log_error,
+ "Customization command failed with exitcode: %d, stderr: %s\n",
+ retval,
+ Process_GetStderr(hp));
}
+
Process_Destroy(hp);
return retval;
}