| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef SPAWN_POPEN_H |
| 4 | #define SPAWN_POPEN_H |
| 5 | |
| 6 | #include "../libnetdata.h" |
| 7 | |
| 8 | extern SPAWN_SERVER *netdata_main_spawn_server; |
| 9 | bool netdata_main_spawn_server_init(const char *name, int argc, const char **argv); |
| 10 | void netdata_main_spawn_server_cleanup(void); |
| 11 | |
| 12 | typedef struct popen_instance POPEN_INSTANCE; |
| 13 | |
| 14 | POPEN_INSTANCE *spawn_popen_run(const char *cmd); |
| 15 | POPEN_INSTANCE *spawn_popen_run_argv(const char **argv); |
| 16 | POPEN_INSTANCE *spawn_popen_run_variadic(const char *cmd, ...); |
| 17 | int spawn_popen_wait(POPEN_INSTANCE *pi); |
| 18 | |
| 19 | // Wait for the child for up to timeout_ms. A non-positive timeout_ms performs a single, minimal |
| 20 | // bounded poll; the wait is always bounded, never infinite. |
| 21 | // SPAWN_TIMEDWAIT_EXITED: the child exited; *code holds its spawn_popen_wait()-style return code |
| 22 | // and pi has been freed. |
| 23 | // SPAWN_TIMEDWAIT_RUNNING: still running after timeout_ms; pi remains valid - call again, or |
| 24 | // spawn_popen_wait()/spawn_popen_kill(). |
| 25 | // SPAWN_TIMEDWAIT_ERROR: the wait could not be completed (the child's state is unknown); pi remains |
| 26 | // valid and the caller must reclaim it with spawn_popen_kill(). Do NOT loop on ERROR. |
| 27 | SPAWN_TIMEDWAIT_RESULT spawn_popen_timedwait(POPEN_INSTANCE *pi, int timeout_ms, int *code); |
| 28 | |
| 29 | int spawn_popen_kill(POPEN_INSTANCE *pi, int timeout_ms); |
| 30 | |
| 31 | pid_t spawn_popen_pid(POPEN_INSTANCE *pi); |
| 32 | int spawn_popen_read_fd(POPEN_INSTANCE *pi); |
| 33 | int spawn_popen_write_fd(POPEN_INSTANCE *pi); |
| 34 | FILE *spawn_popen_stdin(POPEN_INSTANCE *pi); |
| 35 | FILE *spawn_popen_stdout(POPEN_INSTANCE *pi); |
| 36 | |
| 37 | #endif //SPAWN_POPEN_H |