int retval;
int i;
char** args = GetFormattedCommandLine(command);
+ Bool isPerlCommand = (strcmp(args[0], "/usr/bin/perl") == 0) ? true : false;
sLog(log_debug, "Command to exec : '%s'.\n", args[0]);
Process_Create(&hp, args, sLog);
free(args);
Process_RunToComplete(hp, gProcessTimeout);
- sLog(log_info, "Customization command output: '%s'.\n", Process_GetStdout(hp));
+ if (isPerlCommand) {
+ sLog(log_info, "Customization command output:\n\n%s\n\n%s\n%s\n",
+ "=================== Perl script log start =================",
+ Process_GetStdout(hp),
+ "=================== Perl script log end =================");
+ } else {
+ sLog(log_info, "Customization command output:\n'%s'.\n",
+ Process_GetStdout(hp));
+ }
retval = Process_GetExitCode(hp);
if (retval == 0) {
/*********************************************************
- * Copyright (C) 2007-2016,2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 2007-2020 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
READSTATUS_UNDEFINED,
READSTATUS_DONE,
READSTATUS_PENDING,
+ READSTATUS_WAITING_EOF,
READSTATUS_ERROR
} ReadStatus;
ReadStatus res_stdout = READSTATUS_UNDEFINED;
ReadStatus res_stderr = READSTATUS_UNDEFINED;
+ Bool processExitedAbnormally = FALSE;
+
p = (ProcessInternal*)h;
stdout[0] = stdout[1] = 0;
execv(p->args[0], p->args);
// exec failed
+ close(stdout[1]);
+ close(stderr[1]);
exit(127);
}
"Process exited abnormally after %d sec, uncaught signal %d",
elapsedTimeLoopSleeps * LoopSleepMicrosec / OneSecMicroSec,
WTERMSIG(processStatus));
+ processExitedAbnormally = TRUE;
}
break;
}
// Process completed. Now read all the output to EOF.
- ProcessRead(p, &res_stdout, TRUE, TRUE);
+ // PR 2367614, set readToEof to TRUE only if process exits normally.
+ // Otherwise just empty the pipe to avoid being blocked by read operation.
+ ProcessRead(p, &res_stdout, TRUE, !processExitedAbnormally);
if (res_stdout == READSTATUS_ERROR) {
- p->log(log_error, "Error while reading process output, killing...");
+ p->log(log_error, "Error while reading process stdout, killing...");
}
- ProcessRead(p, &res_stderr, FALSE, TRUE);
+ ProcessRead(p, &res_stderr, FALSE, !processExitedAbnormally);
if (res_stderr == READSTATUS_ERROR) {
- p->log(log_error, "Error while reading process output, killing...");
+ p->log(log_error, "Error while reading process stderr, killing...");
}
- close(stdout[1]);
- close(stderr[1]);
+ close(stdout[0]);
+ close(stderr[0]);
return PROCESS_SUCCESS;
}
return;
} else if (count < 0) {
if (errno == EAGAIN && readToEof) {
- if (*status != READSTATUS_PENDING) {
+ if (*status != READSTATUS_WAITING_EOF) {
// waiting for more output, sleep briefly and try again
- p->log(log_info, "Pending output from %s, trying again", stdstr);
- *status = READSTATUS_PENDING;
+ p->log(log_info, "Pending output from %s till EOF, trying again",
+ stdstr);
+ *status = READSTATUS_WAITING_EOF;
}
usleep(1000);