Java Mailing List Archive

http://www.redhatconfig.com/

Home » Ubuntu Technical Support »

bsdutils: /usr/bin/script doesn't wait for command to finish before
 exiting

Fergus Henderson

2008-07-28

Replies: Find Java Web Hosting

Author LoginPost Reply
Package: bsdutils
Version: 1:2.12r-4ubuntu6.1
Severity: normal
Tags: patch


The script command fails to wait for the command that it is executing to finish.
For example, the command

/usr/bin/script -c "sleep 1; echo foo" < /dev/null; echo bar

produces the output

Script started, file is typescript
Script done, file is typescript
bar
foo

and an empty "typescript" file, whereas the correct output should be

Script started, file is typescript
foo
Script done, file is typescript
bar

and the "typescript" file should contain "foo".

The following patch fixes the problem.

--- util-linux-2.12r/misc-utils/script.c  2004-03-26 12:07:16.000000000 -0500
+++ util-linux-2.12r-fergus/misc-utils/script.c  2008-07-28 18:34:38.223254000 -0400
@@(protected) @@
#include <sys/time.h>
#include <sys/file.h>
#include <sys/signal.h>
+#include <sys/wait.h>
+#include <errno.h>
#include "nls.h"

#ifdef __linux__
@@(protected) @@
void doinput(void);
void dooutput(void);
void doshell(void);
+void waitforchild(void);

char  *shell;
FILE  *fscript;
@@(protected) @@
     dooutput();
   else
     doshell();
-  } else
+  } else {
   (void) signal(SIGWINCH, resize);
-  doinput();
+    doinput();
+  }

 return 0;
}
@@(protected) @@

 while ((cc = read(0, ibuf, BUFSIZ)) > 0)
   (void) write(master, ibuf, cc);
+
+  waitforchild();
+
 done();
}

@@(protected) @@
   if (fflg)
     (void) fflush(fscript);
 }
+  waitforchild();
 done();
}

@@(protected) @@
   shname = shell;

 if (cflg)
-    execl(shell, shname, "-c", cflg, 0);
+    execl(shell, shname, "-c", cflg, (const char *)0);
 else
-    execl(shell, shname, "-i", 0);
+    execl(shell, shname, "-i", (const char *)0);

 perror(shell);
 fail();
@@(protected) @@
 (void) setsid();
 (void) ioctl(slave, TIOCSCTTY, 0);
}
+
+void waitforchild() {
+  int err;
+  do {
+    err = waitpid(child, NULL, 0);
+  } while (err == EINTR);
+}


-- System Information:
Debian Release: testing/unstable
APT prefers dapper-updates
APT policy: (500, 'dapper-updates'), (500, 'dapper-security'), (500, 'dapper')
Architecture: i386 (x86_64)
Shell: /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18.5-gg26workstation-mixed64-32
Locale: LANG=en_US, LC_CTYPE=en_US (charmap=ISO-8859-1)

Versions of packages bsdutils depends on:
ii libc6           2.3.6-0ubuntu20-gg2 GNU C Library: Shared libraries an

Versions of packages bsdutils recommends:
ii bsdmainutils           6.1.2ubuntu1 collection of more utilities from

-- debconf-show failed

--
ubuntu-users mailing list
ubuntu-users@(protected)
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
©2008 redhatconfig.com - Jax Systems, LLC, U.S.A.