MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / parent_watchdog_thread

Function parent_watchdog_thread

src/main.c:448–478  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446} parent_watchdog_config_t;
447
448static 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
480static bool worker_prepare_process_group(void) {
481 pid_t process_id = getpid();

Callers

nothing calls this directly

Calls 3

_exitFunction · 0.85
request_shutdownFunction · 0.85
writeFunction · 0.50

Tested by

no test coverage detected