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



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
@@ -52,6 +52,8 @@
#include <sys/time.h>
#include <sys/file.h>
#include <sys/signal.h>
+#include <sys/wait.h>
+#include <errno.h>
#include "nls.h"

#ifdef __linux__
@@ -74,6 +76,7 @@
void doinput(void);
void dooutput(void);
void doshell(void);
+void waitforchild(void);

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

return 0;
}
@@ -224,6 +228,9 @@

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

@@ -293,6 +300,7 @@
if (fflg)
(void) fflush(fscript);
}
+ waitforchild();
done();
}

@@ -325,9 +333,9 @@
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();
@@ -431,3 +439,10 @@
(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@xxxxxxxxxxxxxxxx
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



Relevant Pages

  • Re: CDRECORD errors with "fancy formatted" text files
    ... Instead of being rude to us, why don't you post your command lines for cdrecord ... and mkisofs, and maybe even a ls -la of the dir of the files you're trying to save, ... One way to do it is with script: ... That leaves a file called "typescript" that would give a good start to ...
    (comp.os.linux.hardware)
  • Re: [opensuse] ssl certificate manager gui
    ... making directories, using openssl command line syntax, etc. ... Before you start your lengthy series of commands, type "script" ... there will be a file called "typescript" ... there's a script called "cleanscript" ...
    (SuSE)
  • Re: bsdutils: /usr/bin/script doesnt wait for command to finish before exiting
    ... The script command fails to wait for the command that it is executing to finish. ... Script started, file is typescript ... It is the I/O redirection from /dev/null which is the culprit. ...
    (Ubuntu)
  • Re: Is there a command that record both the output and the command?
    ... and command options have been used to generate the output. ... When the shell session exits, ... Script started, file is typescript ...
    (comp.unix.shell)
  • Re: Command Parser
    ... shortcut to writing the full declaration of 'void function1(Connection ch, ... UserList users, string ARGS)'. ... Then you can instantiate the class with the invariant arguments passed to the constructor or otherwise initialized as part of the instantiation, and then just pass the non-invariant data (the command argument) to each method when it's called. ...
    (microsoft.public.dotnet.languages.csharp)