---
 script.c | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

diff --git a/script.c b/script.c
index 1b42a3b..4899d35 100644
--- a/script.c
+++ b/script.c
@@ -84,7 +84,7 @@ static const char *fname;
 static int     isterm;
 static struct  termios tt;
 
-__dead static void     done(void);
+__dead static void     done(int);
 __dead static void     dooutput(void);
 __dead static void     doshell(const char *);
 __dead static void     fail(void);
@@ -92,7 +92,6 @@ static void   finish(int);
 static void    scriptflush(int);
 static void    record(FILE *, char *, size_t, int);
 static void    consume(FILE *, off_t, char *, int);
-static void    childwait(void);
 __dead static void     playback(FILE *);
 
 int
@@ -205,31 +204,26 @@ main(int argc, char *argv[])
                        record(fscript, ibuf, cc, 'i');
                (void)write(master, ibuf, cc);
        }
-       childwait();
-       return EXIT_SUCCESS;
-}
-
-static void
-childwait(void)
-{
-       sigset_t set;
-
-       sigemptyset(&set);
-       sigsuspend(&set);
+       finish(-1);
 }
 
 static void
 finish(int signo)
 {
-       int die, pid, status;
+       int die, pid, status, cstat;
 
        die = 0;
-       while ((pid = wait3(&status, WNOHANG, 0)) > 0)
-               if (pid == child)
+       while ((pid = wait(&status)) > 0)
+               if (pid == child) {
+                       cstat = status;
                        die = 1;
+               }
 
        if (die)
-               done();
+               if (WIFEXITED(cstat))
+                       done(WEXITSTATUS(cstat));
+               else
+                       done(128 + WTERMSIG(cstat));
 }
 
 static void
@@ -267,8 +261,7 @@ dooutput(void)
                if (flush)
                        (void)fflush(fscript);
        }
-       childwait();
-       exit(EXIT_SUCCESS);
+       finish(-1);
 }
 
 static void
@@ -307,11 +300,11 @@ fail(void)
 {
 
        (void)kill(0, SIGTERM);
-       done();
+       done(EXIT_FAILURE);
 }
 
 static void
-done(void)
+done(int status)
 {
        time_t tvec;
 
@@ -330,7 +323,7 @@ done(void)
                if (!quiet)
                        (void)printf("Script done, output file is %s\n", fname);
        }
-       exit(EXIT_SUCCESS);
+       exit(status);
 }
 
 static void
-- 
2.30.2

Attachment: signature.asc
Description: PGP signature

Reply via email to