From f234bc3e5459e357aae04d83354e1218c51198fa Mon Sep 17 00:00:00 2001 From: bdrewery Date: Tue, 8 Mar 2016 18:05:02 +0000 Subject: Filemon: Attach from the child to avoid racing with the parent attach. This is the same as how the bmake filemon usage works. This also fixes failed attach not properly flushing the TTY. MFC after: 1 week Relnotes: yes Sponsored by: EMC / Isilon Storage Division --- usr.bin/script/script.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'usr.bin/script/script.c') diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 72814fb..49446ef 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -224,13 +224,19 @@ main(int argc, char *argv[]) warn("fork"); done(1); } - if (child == 0) + if (child == 0) { + if (fflg) { + int pid; + + pid = getpid(); + if (ioctl(fm_fd, FILEMON_SET_PID, &pid) < 0) + err(1, "Cannot set filemon PID"); + } + doshell(argv); + } close(slave); - if (fflg && ioctl(fm_fd, FILEMON_SET_PID, &child) < 0) - err(1, "Cannot set filemon PID"); - start = tvec = time(0); readstdin = 1; for (;;) { -- cgit v1.1 From 49a860c3b1235560e6919b9b1c5b06dd585f60ce Mon Sep 17 00:00:00 2001 From: bdrewery Date: Tue, 8 Mar 2016 18:05:20 +0000 Subject: Just exit in the child if execve(2) fails. No functional change. This is mostly addressing a false-positive from the clang static analyzer due to it thinking that done() was being called with freed memory, however the kill(0, SIGTERM) made the done() never reached. It doesn't make sense to the show the footer from the child anyhow, nor does it make sense to kill the process group here since the execve(2) failed in the child. This code was leftover from many years of refactoring. MFC after: 1 week Sponsored by: EMC / Isilon Storage Division --- usr.bin/script/script.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'usr.bin/script/script.c') diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 49446ef..4c5e402 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -80,7 +80,6 @@ static struct termios tt; static void done(int) __dead2; static void doshell(char **); -static void fail(void); static void finish(void); static void record(FILE *, char *, size_t, int); static void consume(FILE *, off_t, char *, int); @@ -347,14 +346,7 @@ doshell(char **av) execl(shell, shell, "-i", (char *)NULL); warn("%s", shell); } - fail(); -} - -static void -fail(void) -{ - (void)kill(0, SIGTERM); - done(1); + exit(1); } static void -- cgit v1.1 From 1d619dcb697aac116b9709634986e7fe26315685 Mon Sep 17 00:00:00 2001 From: bdrewery Date: Tue, 8 Mar 2016 18:05:23 +0000 Subject: Record command exit status in the typescript file when running simple commands. Also capitalize 'command:'. Relnotes: yes MFC after: 2 weeks Sponsored by: EMC / Isilon Storage Division --- usr.bin/script/script.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'usr.bin/script/script.c') diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 4c5e402..6ffb46a 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -74,7 +74,7 @@ static int child; static const char *fname; static char *fmfname; static int fflg, qflg, ttyflg; -static int usesleep, rawout; +static int usesleep, rawout, showexit; static struct termios tt; @@ -107,6 +107,7 @@ main(int argc, char *argv[]) flushtime = 30; fm_fd = -1; /* Shut up stupid "may be used uninitialized" GCC warning. (not needed w/clang) */ + showexit = 0; while ((ch = getopt(argc, argv, "adFfkpqrt:")) != -1) switch(ch) { @@ -198,7 +199,8 @@ main(int argc, char *argv[]) (void)fprintf(fscript, "Script started on %s", ctime(&tvec)); if (argv[0]) { - fprintf(fscript, "command: "); + showexit = 1; + fprintf(fscript, "Command: "); for (k = 0 ; argv[k] ; ++k) fprintf(fscript, "%s%s", k ? " " : "", argv[k]); @@ -360,9 +362,13 @@ done(int eno) if (rawout) record(fscript, NULL, 0, 'e'); if (!qflg) { - if (!rawout) + if (!rawout) { + if (showexit) + (void)fprintf(fscript, "\nCommand exit status:" + " %d", eno); (void)fprintf(fscript,"\nScript done on %s", ctime(&tvec)); + } (void)printf("\nScript done, output file is %s\n", fname); if (fflg) { (void)printf("Filemon done, output file is %s\n", -- cgit v1.1