| 2001 | } |
| 2002 | |
| 2003 | int cbm_subprocess_run(const cbm_proc_opts_t *opts, cbm_proc_result_t *out) { |
| 2004 | cbm_proc_result_t local; |
| 2005 | if (!out) { |
| 2006 | out = &local; |
| 2007 | } |
| 2008 | cbm_subprocess_result_init(out); |
| 2009 | |
| 2010 | cbm_subprocess_t *process = NULL; |
| 2011 | if (cbm_subprocess_spawn(opts, &process) != 0) { |
| 2012 | return -1; |
| 2013 | } |
| 2014 | for (;;) { |
| 2015 | cbm_proc_poll_t state = cbm_subprocess_poll(process, out); |
| 2016 | if (state == CBM_PROC_POLL_TERMINAL) { |
| 2017 | bool supervised = out->tree_quiesced && !out->supervision_failed; |
| 2018 | cbm_subprocess_destroy(process); |
| 2019 | return supervised ? 0 : -1; |
| 2020 | } |
| 2021 | /* A valid owned handle has no ERROR state; invalid-argument errors are |
| 2022 | * rejected before this compatibility loop is entered. */ |
| 2023 | const struct timespec delay = {0, 10000000L}; /* 10 ms */ |
| 2024 | (void)cbm_nanosleep(&delay, NULL); |
| 2025 | } |
| 2026 | } |