]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
script: do not try to close stderr twice
authorSami Kerola <kerolasa@iki.fi>
Tue, 6 Nov 2012 21:14:14 +0000 (21:14 +0000)
committerKarel Zak <kzak@redhat.com>
Thu, 8 Nov 2012 13:51:20 +0000 (14:51 +0100)
The commit cdd2a8c360c70d16804ace7cc923a6c6bb7c9ca9 broke script(1)
return value.

$ script -e -c "echo"; echo $?
1

The reason, as Daniel it reported, was that the script will close stderr
twice, once as timing file and atexit() in function close_stdout().  This
commit fixes the problem.

Reported-by: Daniel Narvaez <dwnarvaez@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
term-utils/script.c

index ccd88738a6a297ef916326c0fba676b9dc79b6e6..94a20da6c3161d9d11170433335c4bdf7863b052 100644 (file)
@@ -159,7 +159,7 @@ main(int argc, char **argv) {
        sigset_t block_mask, unblock_mask;
        struct sigaction sa;
        int ch;
-       FILE *timingfd = stderr;
+       FILE *timingfd = NULL;
 
        enum { FORCE_OPTION = CHAR_MAX + 1 };
 
@@ -274,9 +274,11 @@ main(int argc, char **argv) {
                        warn(_("fork failed"));
                        fail();
                }
-               if (child)
+               if (child) {
+                       if (!timingfd)
+                               timingfd = fdopen(STDERR_FILENO, "w");
                        dooutput(timingfd);
-               else
+               else
                        doshell();
        } else {
                sa.sa_handler = resize;