]> Dogcows Code - chaz/tar/commitdiff
Avoid overwriting exit_status with a value indicating less important condition.
authorSergey Poznyakoff <gray@gnu.org.ua>
Tue, 8 Sep 2009 08:04:48 +0000 (11:04 +0300)
committerSergey Poznyakoff <gray@gnu.org.ua>
Tue, 8 Sep 2009 08:04:48 +0000 (11:04 +0300)
* src/tar.c (set_exit_status): New function.
* src/common.h (set_exit_status): New prototype.
* src/compare.c: Use set_exit_status instead of
exit_status assignments.
* src/create.c: Likewise.
* src/misc.c: Likewise.

* src/system.c (wait_for_grandchild): Use auto variable
instead of the global exit_status.
* src/incremen.c (scan_directory): Use file_removed_diag
instead of stat_diag.

src/common.h
src/compare.c
src/create.c
src/incremen.c
src/misc.c
src/system.c
src/tar.c

index 196c1188c713100a0c4c6985e2e549e13e4c4c74..73865ec87fba6681f0c101332e03c9b331b632a2 100644 (file)
@@ -701,6 +701,7 @@ void usage (int) __attribute__ ((noreturn));
 int tar_timespec_cmp (struct timespec a, struct timespec b);
 const char *archive_format_string (enum archive_format fmt);
 const char *subcommand_string (enum subcommand c);
+void set_exit_status (int val);
 
 /* Module update.c.  */
 
index 57732cccaa7fdadf51c872019252002ace7457e7..cb1f3a8bd2b0b94569067f74bdb6db82a520e679 100644 (file)
@@ -66,8 +66,7 @@ report_difference (struct tar_stat_info *st, const char *fmt, ...)
       fprintf (stdlis, "\n");
     }
 
-  if (exit_status == TAREXIT_SUCCESS)
-    exit_status = TAREXIT_DIFFERS;
+  set_exit_status (TAREXIT_DIFFERS);
 }
 
 /* Take a buffer returned by read_and_process and do nothing with it.  */
index e33122a4ce07ee34a199255a55a4d5a26e74bcb7..6f3113e7f64fafbc222a5d805f8491426477385f 100644 (file)
@@ -1081,7 +1081,7 @@ dump_regular_file (int fd, struct tar_stat_info *st)
                    quotearg_colon (st->orig_file_name),
                    STRINGIFY_BIGINT (size_left, buf)));
          if (! ignore_failed_read_option) 
-           exit_status = TAREXIT_DIFFERS;
+           set_exit_status (TAREXIT_DIFFERS);
          pad_archive (size_left - (bufsize - count));
          return dump_status_short;
        }
@@ -1365,7 +1365,7 @@ unknown_file_error (char const *p)
           (0, 0, _("%s: Unknown file type; file ignored"),
            quotearg_colon (p)));
   if (!ignore_failed_read_option)
-    exit_status = TAREXIT_FAILURE;
+    set_exit_status (TAREXIT_FAILURE);
 }
 
 \f
@@ -1667,8 +1667,7 @@ dump_file0 (struct tar_stat_info *st, const char *p,
              WARNOPT (WARN_FILE_CHANGED,
                       (0, 0, _("%s: file changed as we read it"),
                        quotearg_colon (p)));
-             if (exit_status == TAREXIT_SUCCESS)
-               exit_status = TAREXIT_DIFFERS;
+             set_exit_status (TAREXIT_DIFFERS);
            }
          else if (atime_preserve_option == replace_atime_preserve
                   && set_file_atime (fd, p, restore_times) != 0)
index bb2ba2fe18dc76d688311fa81a2ca64ea9cfaf1d..fcfdaa949321cba4cb99ad6fe4cd3cf44690fb62 100644 (file)
@@ -709,10 +709,7 @@ scan_directory (char *dir, dev_t device, bool cmdline)
   
   if (deref_stat (dereference_option, name_buffer, &stat_data))
     {
-      dir_removed_diag (name_buffer, false, stat_diag);
-      /* FIXME: used to be
-           children = CHANGED_CHILDREN;
-        but changed to: */
+      dir_removed_diag (name_buffer, cmdline, stat_diag);
       free (name_buffer);
       free (dirp);
       return NULL;
@@ -760,7 +757,7 @@ scan_directory (char *dir, dev_t device, bool cmdline)
            {
              if (deref_stat (dereference_option, name_buffer, &stat_data))
                {
-                 stat_diag (name_buffer);
+                 file_removed_diag (name_buffer, false, stat_diag);
                  *entry = 'N';
                  continue;
                }
index 3a23aa4d2fd0664b6b9680f3151484484671c867..a087263556804d251b3a1e0a901b44448c8de18f 100644 (file)
@@ -754,8 +754,7 @@ file_removed_diag (const char *name, bool top_level,
       WARNOPT (WARN_FILE_REMOVED,
               (0, 0, _("%s: File removed before we read it"),
                quotearg_colon (name)));
-      if (exit_status == TAREXIT_SUCCESS)
-       exit_status = TAREXIT_DIFFERS;
+      set_exit_status (TAREXIT_DIFFERS);
     }      
   else
     diagfn (name);
@@ -770,8 +769,7 @@ dir_removed_diag (const char *name, bool top_level,
       WARNOPT (WARN_FILE_REMOVED,
               (0, 0, _("%s: Directory removed before we read it"),
                quotearg_colon (name)));
-      if (exit_status == TAREXIT_SUCCESS)
-       exit_status = TAREXIT_DIFFERS;
+      set_exit_status (TAREXIT_DIFFERS);
     }
   else
     diagfn (name);
index 003f02994e223ea50ab9952e5843781ef0a84451..7df8122bb41e50c382bc1936c17c99de6a979b46 100644 (file)
@@ -290,6 +290,7 @@ void
 wait_for_grandchild (pid_t pid)
 {
   int wait_status;
+  int exit_code = 0;
   
   while (waitpid (pid, &wait_status, 0) == -1)
     if (errno != EINTR)
@@ -301,9 +302,9 @@ wait_for_grandchild (pid_t pid)
   if (WIFSIGNALED (wait_status))
     raise (WTERMSIG (wait_status));
   else if (WEXITSTATUS (wait_status) != 0)
-    exit_status = WEXITSTATUS (wait_status);
+    exit_code = WEXITSTATUS (wait_status);
   
-  exit (exit_status);
+  exit (exit_code);
 }
 
 /* Set ARCHIVE for writing, then compressing an archive.  */
index 583edc90ea6f549e883186d097f10c496a97bd8e..055746188cd55b029d2026deb4ece99a17d148bb 100644 (file)
--- a/src/tar.c
+++ b/src/tar.c
@@ -2577,7 +2577,7 @@ main (int argc, char **argv)
   if (stdlis == stdout)
     close_stdout ();
   else if (ferror (stderr) || fclose (stderr) != 0)
-    exit_status = TAREXIT_FAILURE;
+    set_exit_status (TAREXIT_FAILURE);
 
   return exit_status;
 }
@@ -2615,3 +2615,13 @@ tar_timespec_cmp (struct timespec a, struct timespec b)
     a.tv_nsec = b.tv_nsec = 0;
   return timespec_cmp (a, b);
 }
+
+/* Set tar exit status to VAL, unless it is already indicating
+   a more serious condition. This relies on the fact that the
+   values of TAREXIT_ constants are ranged by severity. */
+void
+set_exit_status (int val)
+{
+  if (val > exit_status)
+    exit_status = val;
+}
This page took 0.030745 seconds and 4 git commands to generate.