From: Sergey Poznyakoff Date: Tue, 8 Sep 2009 08:04:48 +0000 (+0300) Subject: Avoid overwriting exit_status with a value indicating less important condition. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=0d8e3249123ecf0175b60c7b43056ac811eb6921;p=chaz%2Ftar Avoid overwriting exit_status with a value indicating less important condition. * 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. --- diff --git a/src/common.h b/src/common.h index 196c118..73865ec 100644 --- a/src/common.h +++ b/src/common.h @@ -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. */ diff --git a/src/compare.c b/src/compare.c index 57732cc..cb1f3a8 100644 --- a/src/compare.c +++ b/src/compare.c @@ -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. */ diff --git a/src/create.c b/src/create.c index e33122a..6f3113e 100644 --- a/src/create.c +++ b/src/create.c @@ -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); } @@ -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) diff --git a/src/incremen.c b/src/incremen.c index bb2ba2f..fcfdaa9 100644 --- a/src/incremen.c +++ b/src/incremen.c @@ -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; } diff --git a/src/misc.c b/src/misc.c index 3a23aa4..a087263 100644 --- a/src/misc.c +++ b/src/misc.c @@ -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); diff --git a/src/system.c b/src/system.c index 003f029..7df8122 100644 --- a/src/system.c +++ b/src/system.c @@ -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. */ diff --git a/src/tar.c b/src/tar.c index 583edc9..0557461 100644 --- 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; +}