| 1402 | } |
| 1403 | |
| 1404 | int cbm_subprocess_run(const cbm_proc_opts_t *opts, cbm_proc_result_t *out) { |
| 1405 | cbm_proc_result_t local; |
| 1406 | if (!out) { |
| 1407 | out = &local; |
| 1408 | } |
| 1409 | cbm_subprocess_result_init(out); |
| 1410 | |
| 1411 | cbm_subprocess_t *process = NULL; |
| 1412 | if (cbm_subprocess_spawn(opts, &process) != 0) { |
| 1413 | return -1; |
| 1414 | } |
| 1415 | for (;;) { |
| 1416 | cbm_proc_poll_t state = cbm_subprocess_poll(process, out); |
| 1417 | if (state == CBM_PROC_POLL_TERMINAL) { |
| 1418 | bool supervised = out->tree_quiesced && !out->supervision_failed; |
| 1419 | cbm_subprocess_destroy(process); |
| 1420 | return supervised ? 0 : -1; |
| 1421 | } |
| 1422 | /* A valid owned handle has no ERROR state; invalid-argument errors are |
| 1423 | * rejected before this compatibility loop is entered. */ |
| 1424 | const struct timespec delay = {0, 10000000L}; /* 10 ms */ |
| 1425 | (void)cbm_nanosleep(&delay, NULL); |
| 1426 | } |
| 1427 | } |