[Midnightbsd-cvs] src [11428] trunk/usr.bin/script/script.c: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Fri Jul 6 22:47:02 EDT 2018
Revision: 11428
http://svnweb.midnightbsd.org/src/?rev=11428
Author: laffer1
Date: 2018-07-06 22:47:01 -0400 (Fri, 06 Jul 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/usr.bin/script/script.c
Modified: trunk/usr.bin/script/script.c
===================================================================
--- trunk/usr.bin/script/script.c 2018-07-07 02:45:57 UTC (rev 11427)
+++ trunk/usr.bin/script/script.c 2018-07-07 02:47:01 UTC (rev 11428)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 2010, 2012 David E. O'Brien
* Copyright (c) 1980, 1992, 1993
@@ -75,13 +76,12 @@
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;
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);
@@ -109,6 +109,7 @@
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, "adfkpqrt:")) != -1)
switch(ch) {
@@ -159,17 +160,14 @@
asprintf(&fmfname, "%s.filemon", fname);
if (!fmfname)
err(1, "%s.filemon", fname);
- if ((fm_fd = open("/dev/filemon", O_RDWR)) == -1)
+ if ((fm_fd = open("/dev/filemon", O_RDWR | O_CLOEXEC)) == -1)
err(1, "open(\"/dev/filemon\", O_RDWR)");
- if ((fm_log = open(fmfname, O_WRONLY | O_CREAT | O_TRUNC,
+ if ((fm_log = open(fmfname,
+ O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1)
err(1, "open(%s)", fmfname);
if (ioctl(fm_fd, FILEMON_SET_FD, &fm_log) < 0)
err(1, "Cannot set filemon log file descriptor");
-
- /* Set up these two fd's to close on exec. */
- (void)fcntl(fm_fd, F_SETFD, FD_CLOEXEC);
- (void)fcntl(fm_log, F_SETFD, FD_CLOEXEC);
}
if (pflg)
@@ -197,7 +195,8 @@
(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]);
@@ -222,13 +221,19 @@
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 (;;) {
@@ -236,12 +241,15 @@
FD_SET(master, &rfd);
if (readstdin)
FD_SET(STDIN_FILENO, &rfd);
- if ((!readstdin && ttyflg) || flushtime > 0) {
- tv.tv_sec = !readstdin && ttyflg ? 1 :
- flushtime - (tvec - start);
+ if (!readstdin && ttyflg) {
+ tv.tv_sec = 1;
tv.tv_usec = 0;
tvp = &tv;
readstdin = 1;
+ } else if (flushtime > 0) {
+ tv.tv_sec = flushtime - (tvec - start);
+ tv.tv_usec = 0;
+ tvp = &tv;
} else {
tvp = NULL;
}
@@ -334,17 +342,10 @@
execl(shell, shell, "-i", (char *)NULL);
warn("%s", shell);
}
- fail();
+ exit(1);
}
static void
-fail(void)
-{
- (void)kill(0, SIGTERM);
- done(1);
-}
-
-static void
done(int eno)
{
time_t tvec;
@@ -355,9 +356,13 @@
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",
More information about the Midnightbsd-cvs
mailing list