FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 07-28-2008, 10:58 PM
Fergus Henderson
 
Default 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@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 01:34 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org