| 446 | } parent_watchdog_config_t; |
| 447 | |
| 448 | static void *parent_watchdog_thread(void *arg) { |
| 449 | parent_watchdog_config_t config = *(parent_watchdog_config_t *)arg; |
| 450 | const unsigned int poll_interval_us = 500000; /* 500ms */ |
| 451 | |
| 452 | while (!atomic_load(&g_shutdown)) { |
| 453 | cbm_usleep(poll_interval_us); |
| 454 | if (atomic_load(&g_shutdown)) { |
| 455 | break; |
| 456 | } |
| 457 | /* initial_ppid > 1 guards against an already-orphaned start (ppid==1), |
| 458 | * where a changing ppid carries no signal. */ |
| 459 | if (config.initial_ppid > 1 && getppid() != config.initial_ppid) { |
| 460 | static const char msg[] = "level=warn msg=parent.exited reason=ppid_changed\n"; |
| 461 | (void)write(STDERR_FILENO, msg, sizeof(msg) - 1); |
| 462 | if (config.kill_worker_group) { |
| 463 | /* Valid workers establish pgid == pid before any stateful work. |
| 464 | * SIGKILL is deliberate: no non-escaped descendant may continue |
| 465 | * after the owning daemon disappears. */ |
| 466 | (void)kill(-getpid(), SIGKILL); |
| 467 | } |
| 468 | if (config.exit_on_parent_death) { |
| 469 | /* Kernel EOF on every inherited daemon socket is the most |
| 470 | * reliable cancellation signal when an agent disappears. */ |
| 471 | _exit(0); |
| 472 | } |
| 473 | request_shutdown(); |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | return NULL; |
| 478 | } |
| 479 | |
| 480 | static bool worker_prepare_process_group(void) { |
| 481 | pid_t process_id = getpid(); |
nothing calls this directly
no test coverage detected