diff options
author | Eric Jackson <ericj@cvs.openbsd.org> | 2000-03-22 20:25:20 +0000 |
---|---|---|
committer | Eric Jackson <ericj@cvs.openbsd.org> | 2000-03-22 20:25:20 +0000 |
commit | 1cfe22a8faf979e8fc3ffa9c26b0c08ad716d6c8 (patch) | |
tree | 40bd8e2675a9a4518dcd002c799d4600f22ab2cd /usr.bin | |
parent | 33b3583fd559cfc67cbb9d8673bc683c03b37757 (diff) |
Make script give correct return values; adapted from FreeBSD
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/script/script.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c index 62434bc8156..4857f675d76 100644 --- a/usr.bin/script/script.c +++ b/usr.bin/script/script.c @@ -1,4 +1,4 @@ -/* $OpenBSD: script.c,v 1.10 1998/12/19 23:52:03 deraadt Exp $ */ +/* $OpenBSD: script.c,v 1.11 2000/03/22 20:25:19 ericj Exp $ */ /* $NetBSD: script.c,v 1.3 1994/12/21 08:55:43 jtc Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: script.c,v 1.10 1998/12/19 23:52:03 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: script.c,v 1.11 2000/03/22 20:25:19 ericj Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -75,7 +75,7 @@ char *fname; struct termios tt; -__dead void done __P((void)); +__dead void done __P((int)); void dooutput __P((void)); void doshell __P((void)); void fail __P((void)); @@ -147,8 +147,7 @@ main(argc, argv) (void)fclose(fscript); while ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0) (void)write(master, ibuf, cc); - done(); - exit(0); + done(0); } void @@ -157,15 +156,20 @@ finish(signo) { register int die, pid; int save_errno = errno; - int status; + int status, e; - die = 0; + die = e = 0; while ((pid = wait3(&status, WNOHANG, 0)) > 0) - if (pid == child) + if (pid == child) { die = 1; + if (WIFEXITED(status)) + e = WEXITSTATUS(status); + else + e = 1; + } if (die) - done(); + done(e); errno = save_errno; } @@ -194,7 +198,7 @@ dooutput() (void)fwrite(obuf, 1, cc, fscript); outcc += cc; } - done(); + done(0); } void @@ -232,11 +236,12 @@ fail() { (void)kill(0, SIGTERM); - done(); + done(1); } void -done() +done(eval) + int eval; { time_t tvec; @@ -249,6 +254,6 @@ done() (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt); (void)printf("Script done, output file is %s\n", fname); } - exit(0); + exit(eval); } |