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.
This commit is contained in:
@@ -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. */
|
||||
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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. */
|
||||
|
||||
12
src/tar.c
12
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user