Tags: patch

Hi,
the bug where script has a race preventing quick following output from
showing up on the screen or in the file is caused by a missing
synchronisation between child and master ... here is a little script
which only lets the exec happen when output redirection is correctly set
up:

diff -Nurp util-linux-2.13.1/misc-utils/script.c 
util-linux-2.13.1.flo/misc-utils/script.c
--- util-linux-2.13.1/misc-utils/script.c       2008-01-16 10:31:41.000000000 
+0100
+++ util-linux-2.13.1.flo/misc-utils/script.c   2008-02-20 18:32:27.328301482 
+0100
@@ -72,7 +72,7 @@ void fixtty(void);
 void getmaster(void);
 void getslave(void);
 void doinput(void);
-void dooutput(void);
+void dooutput(pid_t cpid);
 void doshell(void);
 
 char   *shell;
@@ -214,7 +214,7 @@ main(int argc, char **argv) {
                        fail();
                }
                if (child)
-                       dooutput();
+                       dooutput(child);
                else
                        doshell();
        } else {
@@ -278,7 +278,7 @@ my_strftime(char *buf, size_t len, const
 }
 
 void
-dooutput() {
+dooutput(pid_t cpid) {
        register int cc;
        time_t tvec;
        char obuf[BUFSIZ];
@@ -295,6 +295,8 @@ dooutput() {
        if (!qflg)
                fprintf(fscript, _("Script started on %s"), obuf);
 
+       kill(cpid, SIGUSR1);
+
        if (die == 0 && child && kill(child, 0) == -1 && errno == ESRCH)
                /*
                 * the SIGCHLD handler could be executed when the "child"
@@ -344,10 +346,18 @@ dooutput() {
        done();
 }
 
+void sig_noaction(int i) {
+       return;
+}
+
 void
 doshell() {
        char *shname;
 
+       signal(SIGUSR1, sig_noaction);
+       pause();
+       signal(SIGUSR1, SIG_DFL);
+
 #if 0
        int t;
 

-- 
Florian Lohoff                  [EMAIL PROTECTED]             +49-171-2280134
        Those who would give up a little freedom to get a little 
          security shall soon have neither - Benjamin Franklin

Attachment: signature.asc
Description: Digital signature

Reply via email to