From: ericj Date: Wed, 22 Mar 2000 20:25:19 +0000 (+0000) Subject: Make script give correct return values; adapted from FreeBSD X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e3989934cdc6d3250736290a07b8a64b09d8db2f;p=openbsd Make script give correct return values; adapted from FreeBSD --- 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 @@ -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); }