From: Karel Zak Date: Tue, 25 Jan 2022 15:05:46 +0000 (+0100) Subject: script: add COMMAND= to log header X-Git-Tag: v2.38-rc1~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4d8edee5eeb3ea5457eeff321bca7dd64108eb8f;p=thirdparty%2Futil-linux.git script: add COMMAND= to log header Fixes: https://github.com/util-linux/util-linux/pull/1566 Co-Author: Henrik Bach Signed-off-by: Karel Zak --- diff --git a/term-utils/script.c b/term-utils/script.c index c8b55c8ef6..6542314121 100644 --- a/term-utils/script.c +++ b/term-utils/script.c @@ -131,6 +131,7 @@ struct script_control { const char *ttyname; const char *ttytype; + const char *command; int ttycols; int ttylines; @@ -389,21 +390,26 @@ static int log_start(struct script_control *ctl, switch (log->format) { case SCRIPT_FMT_RAW: { + int x = 0; char buf[FORMAT_TIMESTAMP_MAX]; time_t tvec = script_time((time_t *)NULL); strtime_iso(&tvec, ISO_TIMESTAMP, buf, sizeof(buf)); fprintf(log->fp, _("Script started on %s ["), buf); + if (ctl->command) + x += fprintf(log->fp, "COMMAND=\"%s\"", ctl->command); + if (ctl->isterm) { init_terminal_info(ctl); if (ctl->ttytype) - fprintf(log->fp, "TERM=\"%s\" ", ctl->ttytype); + x += fprintf(log->fp, "%*sTERM=\"%s\"", !!x, "", ctl->ttytype); if (ctl->ttyname) - fprintf(log->fp, "TTY=\"%s\" ", ctl->ttyname); + x += fprintf(log->fp, "%*sTTY=\"%s\"", !!x, "", ctl->ttyname); - fprintf(log->fp, "COLUMNS=\"%d\" LINES=\"%d\"", ctl->ttycols, ctl->ttylines); + fprintf(log->fp, "%*sCOLUMNS=\"%d\" LINES=\"%d\"", !!x, "", + ctl->ttycols, ctl->ttylines); } else fprintf(log->fp, _("")); @@ -756,7 +762,7 @@ int main(int argc, char **argv) struct ul_pty_callbacks *cb; int ch, format = 0, caught_signal = 0, rc = 0, echo = 1; const char *outfile = NULL, *infile = NULL; - const char *timingfile = NULL, *shell = NULL, *command = NULL; + const char *timingfile = NULL, *shell = NULL; enum { FORCE_OPTION = CHAR_MAX + 1 }; @@ -811,7 +817,7 @@ int main(int argc, char **argv) ctl.append = 1; break; case 'c': - command = optarg; + ctl.command = optarg; break; case 'E': if (strcmp(optarg, "auto") == 0) @@ -969,13 +975,13 @@ int main(int argc, char **argv) shname = shname ? shname + 1 : shell; if (access(shell, X_OK) == 0) { - if (command) - execl(shell, shname, "-c", command, (char *)NULL); + if (ctl.command) + execl(shell, shname, "-c", ctl.command, (char *)NULL); else execl(shell, shname, "-i", (char *)NULL); } else { - if (command) - execlp(shname, "-c", command, (char *)NULL); + if (ctl.command) + execlp(shname, "-c", ctl.command, (char *)NULL); else execlp(shname, "-i", (char *)NULL); } @@ -1010,8 +1016,8 @@ int main(int argc, char **argv) log_info(&ctl, "LINES", "%d", ctl.ttylines); } log_info(&ctl, "SHELL", "%s", shell); - if (command) - log_info(&ctl, "COMMAND", "%s", command); + if (ctl.command) + log_info(&ctl, "COMMAND", "%s", ctl.command); log_info(&ctl, "TIMING_LOG", "%s", timingfile); if (outfile) log_info(&ctl, "OUTPUT_LOG", "%s", outfile);