util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: Daniel Narvaez <dwnarvaez@gmail.com>, Sami Kerola <kerolasa@iki.fi>
Subject: [PATCH] script: do not try to close stderr twice
Date: Tue,  6 Nov 2012 21:14:14 +0000	[thread overview]
Message-ID: <1352236454-28312-1-git-send-email-kerolasa@iki.fi> (raw)

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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/term-utils/script.c b/term-utils/script.c
index ccd8873..94a20da 100644
--- a/term-utils/script.c
+++ b/term-utils/script.c
@@ -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;
-- 
1.8.0


             reply	other threads:[~2012-11-06 21:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-06 21:14 Sami Kerola [this message]
2012-11-08 13:52 ` [PATCH] script: do not try to close stderr twice Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1352236454-28312-1-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --cc=dwnarvaez@gmail.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).