[coreutils] dd exit


coreutils-7.5 (fixed in 7.6)

How to reproduce?

When use dd if=file1 of=file2 2>errFile.txt command, before outputing the summary msg, if we delete the errFile.txt, dd still exit normally without warning, with exit status == 0.


dd exit normally with exit_status being 0 when it encounters a write error when writing the dd summary to stderr.

Root cause:

At the exit, it only closed stdout, but did not bother to close stderr.

static void maybe_close_stdout (void)


 if (close_stdout_required)

   close_stdout ();

/* In the buggy version, the stderr is not even closed.

* So any errors during closing

* stderr will not be reported. */

+  else if (close_stream (stderr) != 0)

+    _exit (EXIT_FAILURE);


main (...) {

  /* atexit() register a function to be called at the exit. */



Is there Error Message?


Can Errlog print an error message?

Yes. We annotate the atexit call (which will use the on_exit library call). So we know that maybe_close_stdout is a exit function and we put a message in it.