| 201 | } |
| 202 | |
| 203 | static void |
| 204 | cleanup (int sig) |
| 205 | { |
| 206 | if (sig == SIGALRM) |
| 207 | { |
| 208 | timed_out = 1; |
| 209 | /* In case there is an issue with close_stdout, |
| 210 | update to a more accurate default exit status. |
| 211 | For example we might get failed writes with -v with: |
| 212 | timeout -v 1 sleep 10 2>&1 | : |
| 213 | */ |
| 214 | initialize_exit_failure (EXIT_TIMEDOUT); |
| 215 | sig = term_signal; |
| 216 | } |
| 217 | if (0 < monitored_pid) |
| 218 | { |
| 219 | if (kill_after) |
| 220 | { |
| 221 | int saved_errno = errno; /* settimeout may reset. */ |
| 222 | /* Start a new timeout after which we'll send SIGKILL. */ |
| 223 | term_signal = SIGKILL; |
| 224 | settimeout (kill_after, false); |
| 225 | kill_after = 0; /* Don't let later signals reset kill alarm. */ |
| 226 | errno = saved_errno; |
| 227 | } |
| 228 | |
| 229 | /* Send the signal directly to the monitored child, |
| 230 | in case it has itself become group leader, |
| 231 | or is not running in a separate group. */ |
| 232 | if (verbose) |
| 233 | { |
| 234 | char signame[MAX (SIG2STR_MAX, INT_BUFSIZE_BOUND (int))]; |
| 235 | if (sig == 0 || sig2str (sig, signame) != 0) |
| 236 | snprintf (signame, sizeof signame, "%d", sig); |
| 237 | error (0, 0, _("sending signal %s to command %s"), |
| 238 | signame, quote (command)); |
| 239 | } |
| 240 | send_sig (monitored_pid, sig); |
| 241 | |
| 242 | /* The normal case is the job has remained in our |
| 243 | newly created process group, so send to all processes in that. */ |
| 244 | if (!foreground) |
| 245 | { |
| 246 | send_sig (0, sig); |
| 247 | if (sig != SIGKILL && sig != SIGCONT) |
| 248 | { |
| 249 | send_sig (monitored_pid, SIGCONT); |
| 250 | send_sig (0, SIGCONT); |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | else if (monitored_pid == -1) |
| 255 | { /* were in the parent, so let it continue to exit below. */ |
| 256 | } |
| 257 | else /* monitored_pid == 0 */ |
| 258 | { /* parent hasn't forked yet, or child has not exec'd yet. */ |
| 259 | _exit (128 + sig); |
| 260 | } |
nothing calls this directly
no test coverage detected