summaryrefslogtreecommitdiff
path: root/src/dd.c
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-08-28 10:59:16 -0600
committerEric Blake <ebb9@byu.net>2009-08-28 12:56:51 -0600
commit31fa922e5765a24786061a4dfbd048869457cf84 (patch)
tree906654cadaeaa4fc23dbb0120ab7ffa6558fe4c6 /src/dd.c
parent59a6ddfca34bea0d657cf4d9f56aa6d5bab4a7a1 (diff)
downloadcoreutils-31fa922e5765a24786061a4dfbd048869457cf84.tar.xz
dd: detect closed stderr
* src/dd.c (maybe_close_stdout): Always flush stderr; regression introduced in commit 381e69ea. * tests/misc/close-stdout (p): Use consistent style. * tests/dd/stderr: New test, borrowing from misc/close-stdout. * tests/Makefile.am (TESTS): Run it. * NEWS: Mention this.
Diffstat (limited to 'src/dd.c')
-rw-r--r--src/dd.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/dd.c b/src/dd.c
index dc15cfdf1..d2f566eac 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -25,6 +25,7 @@
#include <getopt.h>
#include "system.h"
+#include "close-stream.h"
#include "error.h"
#include "fd-reopen.h"
#include "gethrxtime.h"
@@ -444,12 +445,16 @@ static bool close_stdout_required = true;
close_stdout function call "fclose (stdout)" would result in a
harmless failure of the close syscall (with errno EBADF).
This function serves solely to avoid the unnecessary close_stdout
- call, once parse_long_options has succeeded. */
+ call, once parse_long_options has succeeded.
+ Meanwhile, we guarantee that the standard error stream is flushed,
+ by inlining the last half of close_stdout as needed. */
static void
maybe_close_stdout (void)
{
if (close_stdout_required)
close_stdout ();
+ else if (close_stream (stderr) != 0)
+ _exit (EXIT_FAILURE);
}
void