| 1435 | } |
| 1436 | |
| 1437 | int cbm_subprocess_run(const cbm_proc_opts_t *opts, cbm_proc_result_t *out) { |
| 1438 | cbm_proc_result_t local; |
| 1439 | if (!out) { |
| 1440 | out = &local; |
| 1441 | } |
| 1442 | cbm_subprocess_result_init(out); |
| 1443 | |
| 1444 | cbm_subprocess_t *process = NULL; |
| 1445 | if (cbm_subprocess_spawn(opts, &process) != 0) { |
| 1446 | return -1; |
| 1447 | } |
| 1448 | for (;;) { |
| 1449 | cbm_proc_poll_t state = cbm_subprocess_poll(process, out); |
| 1450 | if (state == CBM_PROC_POLL_TERMINAL) { |
| 1451 | bool supervised = out->tree_quiesced && !out->supervision_failed; |
| 1452 | cbm_subprocess_destroy(process); |
| 1453 | return supervised ? 0 : -1; |
| 1454 | } |
| 1455 | /* A valid owned handle has no ERROR state; invalid-argument errors are |
| 1456 | * rejected before this compatibility loop is entered. */ |
| 1457 | const struct timespec delay = {0, 10000000L}; /* 10 ms */ |
| 1458 | (void)cbm_nanosleep(&delay, NULL); |
| 1459 | } |
| 1460 | } |