| 1449 | } |
| 1450 | |
| 1451 | int cbm_subprocess_run(const cbm_proc_opts_t *opts, cbm_proc_result_t *out) { |
| 1452 | cbm_proc_result_t local; |
| 1453 | if (!out) { |
| 1454 | out = &local; |
| 1455 | } |
| 1456 | cbm_subprocess_result_init(out); |
| 1457 | |
| 1458 | cbm_subprocess_t *process = NULL; |
| 1459 | if (cbm_subprocess_spawn(opts, &process) != 0) { |
| 1460 | return -1; |
| 1461 | } |
| 1462 | for (;;) { |
| 1463 | cbm_proc_poll_t state = cbm_subprocess_poll(process, out); |
| 1464 | if (state == CBM_PROC_POLL_TERMINAL) { |
| 1465 | bool supervised = out->tree_quiesced && !out->supervision_failed; |
| 1466 | cbm_subprocess_destroy(process); |
| 1467 | return supervised ? 0 : -1; |
| 1468 | } |
| 1469 | /* A valid owned handle has no ERROR state; invalid-argument errors are |
| 1470 | * rejected before this compatibility loop is entered. */ |
| 1471 | const struct timespec delay = {0, 10000000L}; /* 10 ms */ |
| 1472 | (void)cbm_nanosleep(&delay, NULL); |
| 1473 | } |
| 1474 | } |