* 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.
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. */
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. */
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;
}
(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
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)
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;
{
if (deref_stat (dereference_option, name_buffer, &stat_data))
{
- stat_diag (name_buffer);
+ file_removed_diag (name_buffer, false, stat_diag);
*entry = 'N';
continue;
}
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);
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);
wait_for_grandchild (pid_t pid)
{
int wait_status;
+ int exit_code = 0;
while (waitpid (pid, &wait_status, 0) == -1)
if (errno != EINTR)
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. */
if (stdlis == stdout)
close_stdout ();
else if (ferror (stderr) || fclose (stderr) != 0)
- exit_status = TAREXIT_FAILURE;
+ set_exit_status (TAREXIT_FAILURE);
return exit_status;
}
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;
+}