[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Don't error out if stdin/stdout/stderr was already closed.
From: |
James Youngman |
Subject: |
[PATCH] Don't error out if stdin/stdout/stderr was already closed. |
Date: |
Sun, 11 Apr 2010 12:37:25 +0100 |
* lib/closeout.c (close_stdout): Don't signal an error closing
stdout or stderr if it was already closed.
* lib/closein.c (close_stdin): Don't signal an error closing stdin
if it was already closed.
* lib/close-stream.c (close_stream): Make boolean variables const
to document the fact that we set but do not change them.
Signed-off-by: James Youngman <address@hidden>
---
ChangeLog | 10 ++++++++++
lib/close-stream.c | 6 +++---
lib/closein.c | 4 +++-
lib/closeout.c | 9 +++++++--
4 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dd0264b..669a8d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-04-11 James Youngman <address@hidden>
+
+ Don't error out if stdin/stdout/stderr was already closed.
+ * lib/closeout.c (close_stdout): Don't signal an error closing
+ stdout or stderr if it was already closed.
+ * lib/closein.c (close_stdin): Don't signal an error closing stdin
+ if it was already closed.
+ * lib/close-stream.c (close_stream): Make boolean variables const
+ to document the fact that we set but do not change them.
+
2010-04-10 Bruno Haible <address@hidden>
Don't override improved macro from newer autoconf.
diff --git a/lib/close-stream.c b/lib/close-stream.c
index cf0422f..87a59e4 100644
--- a/lib/close-stream.c
+++ b/lib/close-stream.c
@@ -55,9 +55,9 @@
int
close_stream (FILE *stream)
{
- bool some_pending = (__fpending (stream) != 0);
- bool prev_fail = (ferror (stream) != 0);
- bool fclose_fail = (fclose (stream) != 0);
+ const bool some_pending = (__fpending (stream) != 0);
+ const bool prev_fail = (ferror (stream) != 0);
+ const bool fclose_fail = (fclose (stream) != 0);
/* Return an error indication if there was a previous failure or if
fclose failed, with one exception: ignore an fclose failure if
diff --git a/lib/closein.c b/lib/closein.c
index 077a324..5c6b34c 100644
--- a/lib/closein.c
+++ b/lib/closein.c
@@ -92,7 +92,9 @@ close_stdin (void)
}
if (close_stream (stdin) != 0)
fail = true;
- if (fail)
+ if (fail
+ /* Don't signal an error if stdin is already closed. */
+ && (EBADF != errno))
{
/* Report failure, but defer exit until after closing stdout,
since the failure report should still be flushed. */
diff --git a/lib/closeout.c b/lib/closeout.c
index 18a8912..1837f8c 100644
--- a/lib/closeout.c
+++ b/lib/closeout.c
@@ -107,7 +107,8 @@ void
close_stdout (void)
{
if (close_stream (stdout) != 0
- && !(ignore_EPIPE && errno == EPIPE))
+ && !(ignore_EPIPE && errno == EPIPE)
+ && (EBADF != errno))
{
char const *write_error = _("write error");
if (file_name)
@@ -120,5 +121,9 @@ close_stdout (void)
}
if (close_stream (stderr) != 0)
- _exit (exit_failure);
+ {
+ /* If we fail to close stderr because it was already closed, that's OK
*/
+ if (EBADF != errno)
+ _exit (exit_failure);
+ }
}
--
1.7.0
- [PATCH] Don't error out if stdin/stdout/stderr was already closed.,
James Youngman <=