-/* $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 $ */
/*
#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>
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));
(void)fclose(fscript);
while ((cc = read(STDIN_FILENO, ibuf, BUFSIZ)) > 0)
(void)write(master, ibuf, cc);
- done();
- exit(0);
+ done(0);
}
void
{
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;
}
(void)fwrite(obuf, 1, cc, fscript);
outcc += cc;
}
- done();
+ done(0);
}
void
{
(void)kill(0, SIGTERM);
- done();
+ done(1);
}
void
-done()
+done(eval)
+ int eval;
{
time_t tvec;
(void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &tt);
(void)printf("Script done, output file is %s\n", fname);
}
- exit(0);
+ exit(eval);
}