| 1304 | } |
| 1305 | |
| 1306 | int cbm_subprocess_run(const cbm_proc_opts_t *opts, cbm_proc_result_t *out) { |
| 1307 | cbm_proc_result_t local; |
| 1308 | if (!out) { |
| 1309 | out = &local; |
| 1310 | } |
| 1311 | cbm_subprocess_result_init(out); |
| 1312 | |
| 1313 | cbm_subprocess_t *process = NULL; |
| 1314 | if (cbm_subprocess_spawn(opts, &process) != 0) { |
| 1315 | return -1; |
| 1316 | } |
| 1317 | for (;;) { |
| 1318 | cbm_proc_poll_t state = cbm_subprocess_poll(process, out); |
| 1319 | if (state == CBM_PROC_POLL_TERMINAL) { |
| 1320 | bool supervised = out->tree_quiesced && !out->supervision_failed; |
| 1321 | cbm_subprocess_destroy(process); |
| 1322 | return supervised ? 0 : -1; |
| 1323 | } |
| 1324 | /* A valid owned handle has no ERROR state; invalid-argument errors are |
| 1325 | * rejected before this compatibility loop is entered. */ |
| 1326 | const struct timespec delay = {0, 10000000L}; /* 10 ms */ |
| 1327 | (void)cbm_nanosleep(&delay, NULL); |
| 1328 | } |
| 1329 | } |