Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/script PR/55605: Soumendra Ganguly: Wait for child t...



details:   https://anonhg.NetBSD.org/src/rev/786b4ff75424
branches:  trunk
changeset: 937899:786b4ff75424
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Aug 28 17:10:15 2020 +0000

description:
PR/55605: Soumendra Ganguly: Wait for child to finish when stdin is not a tty

diffstat:

 usr.bin/script/script.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (67 lines):

diff -r 2b446c88b6b0 -r 786b4ff75424 usr.bin/script/script.c
--- a/usr.bin/script/script.c   Fri Aug 28 17:05:32 2020 +0000
+++ b/usr.bin/script/script.c   Fri Aug 28 17:10:15 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: script.c,v 1.26 2020/08/08 16:01:35 christos Exp $     */
+/*     $NetBSD: script.c,v 1.27 2020/08/28 17:10:15 christos Exp $     */
 
 /*
  * Copyright (c) 1980, 1992, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)script.c   8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: script.c,v 1.26 2020/08/08 16:01:35 christos Exp $");
+__RCSID("$NetBSD: script.c,v 1.27 2020/08/28 17:10:15 christos Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -92,6 +92,7 @@
 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
@@ -204,12 +205,21 @@
                        record(fscript, ibuf, cc, 'i');
                (void)write(master, ibuf, cc);
        }
-       done();
+       childwait();
        /* NOTREACHED */
        return EXIT_SUCCESS;
 }
 
 static void
+childwait(void)
+{
+       sigset_t set;
+
+       sigemptyset(&set);
+       sigsuspend(&set);
+}
+
+static void
 finish(int signo)
 {
        int die, pid, status;
@@ -249,7 +259,7 @@
                if (scc <= 0)
                        break;
                cc = (size_t)scc;
-               (void)write(1, obuf, cc);
+               (void)write(STDOUT_FILENO, obuf, cc);
                if (rawout)
                        record(fscript, obuf, cc, 'o');
                else
@@ -258,7 +268,7 @@
                if (flush)
                        (void)fflush(fscript);
        }
-       done();
+       childwait();
 }
 
 static void



Home | Main Index | Thread Index | Old Index