- int ocode = code;
- extern int keep_partial;
- extern int log_got_error;
-
- signal(SIGUSR1, SIG_IGN);
- signal(SIGUSR2, SIG_IGN);
-
- if (verbose > 3)
- rprintf(FINFO,"_exit_cleanup(code=%d, file=%s, line=%d): entered\n",
- code, file, line);
-
- if (cleanup_child_pid != -1) {
- int status;
- if (waitpid(cleanup_child_pid, &status, WNOHANG) == cleanup_child_pid) {
- status = WEXITSTATUS(status);
- if (status > code) code = status;
+ static int cleanup_step = 0;
+ static int exit_code = 0;
+ static int unmodified_code = 0;
+
+ SIGACTION(SIGUSR1, SIG_IGN);
+ SIGACTION(SIGUSR2, SIG_IGN);
+
+ if (exit_code) /* Preserve first error code when recursing. */
+ code = exit_code;
+
+ /* If this is the exit at the end of the run, the server side
+ * should not attempt to output a message (see log.c). */
+ if (am_server && code == 0)
+ am_server = 2;
+
+ /* Some of our actions might cause a recursive call back here, so we
+ * keep track of where we are in the cleanup and never repeat a step. */
+ switch (cleanup_step) {
+#include "case_N.h" /* case 0: cleanup_step++; */
+
+ exit_code = unmodified_code = code;
+
+ if (progress_is_active && exit_code && !am_server)
+ rprintf(FINFO, "\n");
+
+ if (verbose > 3) {
+ rprintf(FINFO,
+ "_exit_cleanup(code=%d, file=%s, line=%d): entered\n",
+ code, file, line);