| 279 | } |
| 280 | |
| 281 | static bool wait_for_tree_pids(const char *path, cbm_subprocess_t *process, pid_t *parent_pid, |
| 282 | pid_t *grandchild_pid, int timeout_ms) { |
| 283 | uint64_t deadline = cbm_now_ms() + (uint64_t)timeout_ms; |
| 284 | do { |
| 285 | FILE *f = fopen(path, "r"); |
| 286 | if (f) { |
| 287 | long parent_value = 0; |
| 288 | long grandchild_value = 0; |
| 289 | int fields = fscanf(f, "%ld %ld", &parent_value, &grandchild_value); |
| 290 | fclose(f); |
| 291 | if (fields == 2 && parent_value > 1 && grandchild_value > 1) { |
| 292 | *parent_pid = (pid_t)parent_value; |
| 293 | *grandchild_pid = (pid_t)grandchild_value; |
| 294 | return true; |
| 295 | } |
| 296 | } |
| 297 | cbm_proc_result_t ignored; |
| 298 | if (cbm_subprocess_poll(process, &ignored) != CBM_PROC_POLL_RUNNING) { |
| 299 | return false; |
| 300 | } |
| 301 | subprocess_test_pause(); |
| 302 | } while (cbm_now_ms() < deadline); |
| 303 | return false; |
| 304 | } |
| 305 | |
| 306 | static bool wait_pid_gone(pid_t pid, int timeout_ms) { |
| 307 | uint64_t deadline = cbm_now_ms() + (uint64_t)timeout_ms; |
no test coverage detected