| 254 | } |
| 255 | |
| 256 | static void NONRET |
| 257 | box_exit(int rc) |
| 258 | { |
| 259 | if (proxy_pid > 0) |
| 260 | { |
| 261 | if (box_pid > 0) |
| 262 | { |
| 263 | kill(-box_pid, SIGKILL); |
| 264 | kill(box_pid, SIGKILL); |
| 265 | } |
| 266 | if (cg_enable) |
| 267 | { |
| 268 | /* |
| 269 | * In non-CG mode, we must not kill the proxy explicitly. |
| 270 | * This is important, because the proxy could exit before the box |
| 271 | * completes its exit, causing rusage of the box to be lost. |
| 272 | * |
| 273 | * In CG mode, we must kill the proxy, because it is the init |
| 274 | * process of the CG and killing it causes all other processes |
| 275 | * inside the CG to be killed. However, we do not care about |
| 276 | * rusage. |
| 277 | */ |
| 278 | kill(-proxy_pid, SIGKILL); |
| 279 | kill(proxy_pid, SIGKILL); |
| 280 | } |
| 281 | meta_printf("killed:1\n"); |
| 282 | |
| 283 | /* |
| 284 | * The rusage will contain time spent by the proxy and its children (i.e., the box). |
| 285 | * (See comments on killing of the proxy above, though.) |
| 286 | */ |
| 287 | struct rusage rus; |
| 288 | int p, stat; |
| 289 | do |
| 290 | p = wait4(proxy_pid, &stat, 0, &rus); |
| 291 | while (p < 0 && errno == EINTR); |
| 292 | if (p < 0) |
| 293 | fprintf(stderr, "UGH: Lost track of the process (%m)\n"); |
| 294 | else |
| 295 | final_stats(&rus); |
| 296 | } |
| 297 | |
| 298 | if (tty_hack && isatty(1)) |
| 299 | { |
| 300 | /* |
| 301 | * If stdout is a tty, make us the foreground process group again. |
| 302 | * We do not need it (we ignore SIGTTOU anyway), but programs executed |
| 303 | * after our exit will. |
| 304 | */ |
| 305 | tcsetpgrp(1, getpgrp()); |
| 306 | } |
| 307 | |
| 308 | if (rc < 2 && cleanup_ownership) |
| 309 | chowntree("box", orig_uid, orig_gid, special_files); |
| 310 | |
| 311 | meta_close(); |
| 312 | exit(rc); |
| 313 | } |
no test coverage detected
searching dependent graphs…