bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] unnecessary stdout closing


From: pacman
Subject: [Bug-tar] unnecessary stdout closing
Date: Fri, 19 Mar 2004 18:39:04 -0500 (EST)

I ran tar in an environment where there was no stdin/stdout/stderr, expecting
to use its exit code as an indicator of success. Unfortunately, tar wants to
fclose stdout before exiting, even if it did not need stdout. When the fclose
generates an EBADF, tar exits with a failure code, even though nothing bad
happened - just the expected result of closing a file descriptor that didn't
exist. This command demonstrates the bug:

  mkdir empty ; cd empty ; tar cf /tmp/foo.tar . >&-

The following patch avoids attempting to fclose stdout when no options were
given that would cause it to be used. Another approach would be to open
/dev/null near the beginning of main(), so there will be something to close.

diff -ru tar-1.13.93/src/tar.c tar-1.13.93.pac/src/tar.c
--- tar-1.13.93/src/tar.c       Fri Feb 20 09:46:15 2004
+++ tar-1.13.93.pac/src/tar.c   Fri Mar 19 18:23:26 2004
@@ -1546,7 +1546,12 @@
   free (archive_name_array);
   name_term ();
 
-  if (stdlis != stderr && (ferror (stdlis) || fclose (stdlis) != 0))
+  if (stdlis != stderr &&
+      (verbose_option || verify_option ||
+       block_number_option || interactive_option ||
+       subcommand_option == DIFF_SUBCOMMAND ||
+       subcommand_option == LIST_SUBCOMMAND) &&
+      (ferror (stdlis) || fclose (stdlis) != 0))
     FATAL_ERROR ((0, 0, _("Error in writing to standard output")));
   if (exit_status == TAREXIT_FAILURE)
     error (0, 0, _("Error exit delayed from previous errors"));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]