* Eventually calls exit(), passing @p code, therefore does not return. * * @param code one of the RERR_* codes from errcode.h. **/
| 101 | * @param code one of the RERR_* codes from errcode.h. |
| 102 | **/ |
| 103 | NORETURN void _exit_cleanup(int code, const char *file, int line) |
| 104 | { |
| 105 | static int switch_step = 0; |
| 106 | static int exit_code = 0, exit_line = 0; |
| 107 | static const char *exit_file = NULL; |
| 108 | static int first_code = 0; |
| 109 | |
| 110 | SIGACTION(SIGUSR1, SIG_IGN); |
| 111 | SIGACTION(SIGUSR2, SIG_IGN); |
| 112 | |
| 113 | if (!exit_code) { /* Preserve first error exit info when recursing. */ |
| 114 | exit_code = code; |
| 115 | exit_file = file; |
| 116 | exit_line = line < 0 ? -line : line; |
| 117 | } |
| 118 | |
| 119 | /* If this is the exit at the end of the run, the server side |
| 120 | * should not attempt to output a message (see log_exit()). */ |
| 121 | if (am_server && code == 0) |
| 122 | am_server = 2; |
| 123 | |
| 124 | /* Some of our actions might cause a recursive call back here, so we |
| 125 | * keep track of where we are in the cleanup and never repeat a step. */ |
| 126 | switch (switch_step) { |
| 127 | #include "case_N.h" /* case 0: */ |
| 128 | switch_step++; |
| 129 | |
| 130 | first_code = code; |
| 131 | |
| 132 | if (output_needs_newline) { |
| 133 | fputc('\n', stdout); |
| 134 | output_needs_newline = 0; |
| 135 | } |
| 136 | |
| 137 | if (DEBUG_GTE(EXIT, 2)) { |
| 138 | rprintf(FINFO, |
| 139 | "[%s] _exit_cleanup(code=%d, file=%s, line=%d): entered\n", |
| 140 | who_am_i(), code, src_file(file), line); |
| 141 | } |
| 142 | |
| 143 | #include "case_N.h" |
| 144 | switch_step++; |
| 145 | |
| 146 | if (cleanup_child_pid != -1) { |
| 147 | int status; |
| 148 | int pid = wait_process(cleanup_child_pid, &status, WNOHANG); |
| 149 | if (pid == cleanup_child_pid) { |
| 150 | status = WEXITSTATUS(status); |
| 151 | if (status > exit_code) |
| 152 | exit_code = status; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | #include "case_N.h" |
| 157 | switch_step++; |
| 158 | |
| 159 | if (cleanup_got_literal && (cleanup_fname || cleanup_fd_w != -1)) { |
| 160 | if (cleanup_fd_r != -1) { |
nothing calls this directly
no test coverage detected