| 240 | } |
| 241 | |
| 242 | static bool wait_for_tree_pids(const char *path, cbm_subprocess_t *process, pid_t *parent_pid, |
| 243 | pid_t *grandchild_pid, int timeout_ms) { |
| 244 | uint64_t deadline = cbm_now_ms() + (uint64_t)timeout_ms; |
| 245 | do { |
| 246 | FILE *f = fopen(path, "r"); |
| 247 | if (f) { |
| 248 | long parent_value = 0; |
| 249 | long grandchild_value = 0; |
| 250 | int fields = fscanf(f, "%ld %ld", &parent_value, &grandchild_value); |
| 251 | fclose(f); |
| 252 | if (fields == 2 && parent_value > 1 && grandchild_value > 1) { |
| 253 | *parent_pid = (pid_t)parent_value; |
| 254 | *grandchild_pid = (pid_t)grandchild_value; |
| 255 | return true; |
| 256 | } |
| 257 | } |
| 258 | cbm_proc_result_t ignored; |
| 259 | if (cbm_subprocess_poll(process, &ignored) != CBM_PROC_POLL_RUNNING) { |
| 260 | return false; |
| 261 | } |
| 262 | subprocess_test_pause(); |
| 263 | } while (cbm_now_ms() < deadline); |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | static bool wait_pid_gone(pid_t pid, int timeout_ms) { |
| 268 | uint64_t deadline = cbm_now_ms() + (uint64_t)timeout_ms; |
no test coverage detected