[coreutils] dd exit

Version:

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.

Symptom:

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. */

  atexit(maybe_close_stdout);

}

Is there Error Message?

No

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.