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

Function cbm_subprocess_poll_posix

src/foundation/subprocess.c:1298–1346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1296}
1297
1298static cbm_proc_poll_t cbm_subprocess_poll_posix(cbm_subprocess_t *process,
1299 cbm_proc_result_t *out) {
1300 uint64_t now = cbm_now_ms();
1301
1302 if (!process->root_reaped) {
1303 int status = 0;
1304 pid_t waited = waitpid(process->pid, &status, WNOHANG);
1305 if (waited == process->pid) {
1306 cbm_posix_capture_root(process, status);
1307 } else if (waited < 0 && errno != EINTR) {
1308 /* ECHILD means another reaper consumed the status. Other permanent
1309 * wait failures are treated the same: retain containment, stop the
1310 * tree, and never spin forever on the failed wait operation. */
1311 process->root_reaped = true;
1312 process->result.outcome = process->timed_out ? CBM_PROC_HANG : CBM_PROC_KILLED;
1313 process->result.exit_code = -1;
1314 process->result.term_signal = 0;
1315 cbm_posix_begin_termination(process, now);
1316 }
1317 }
1318
1319 bool group_active = cbm_posix_group_active(process);
1320 if (!process->termination_started) {
1321 if (cbm_subprocess_cancellation_requested(process)) {
1322 cbm_posix_begin_termination(process, now);
1323 } else if (!process->root_reaped && process->quiet_timeout_ms > 0 &&
1324 now - process->last_activity_ms >= (uint64_t)process->quiet_timeout_ms) {
1325 process->timed_out = true;
1326 cbm_posix_begin_termination(process, now);
1327 } else if (process->root_reaped && group_active) {
1328 /* A root that daemonizes children is not terminal. Preserve its exit
1329 * classification, but drain the descendants through the same path. */
1330 cbm_posix_begin_termination(process, now);
1331 }
1332 }
1333 if (process->termination_started && group_active && !process->force_sent &&
1334 now - process->termination_started_ms >= (uint64_t)process->cancel_grace_ms) {
1335 cbm_posix_force_tree(process, now);
1336 }
1337 group_active = cbm_posix_group_active(process);
1338 if (process->force_started_ms != 0 && group_active &&
1339 now - process->force_started_ms >= CBM_SUBPROCESS_FORCE_SETTLE_MS) {
1340 return cbm_subprocess_finish_failed(process, out);
1341 }
1342 if (process->root_reaped && !group_active) {
1343 return cbm_subprocess_finish(process, out);
1344 }
1345 return CBM_PROC_POLL_RUNNING;
1346}
1347
1348#endif /* _WIN32 */
1349

Callers 1

cbm_subprocess_pollFunction · 0.85

Calls 8

cbm_now_msFunction · 0.85
cbm_posix_capture_rootFunction · 0.85
cbm_posix_group_activeFunction · 0.85
cbm_posix_force_treeFunction · 0.85
cbm_subprocess_finishFunction · 0.85

Tested by

no test coverage detected