X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=lib%2Fprocess%2Fprocess.h;h=eb6e3360d73c914e8f3421d5cf2d4e447eb2fc75;hp=65fdba8d537beeb9e43efe9d3f3b08429d143530;hb=ba8144f917f5603e507e9c72aed4ae3257c6b0ce;hpb=0ba871a497f156dd474a333889cd92eaab9b08dc diff --git a/lib/process/process.h b/lib/process/process.h index 65fdba8..eb6e336 100644 --- a/lib/process/process.h +++ b/lib/process/process.h @@ -27,16 +27,23 @@ struct process_info; typedef void (*process_exit_cb)(struct process *); +struct process_stdout { + size_t len; + char *buf; +}; + struct process { /* caller-provided configuration */ const char *path; const char **argv; bool keep_stdout; bool add_stderr; + bool raw_stdout; process_exit_cb exit_cb; void *data; waiter_cb stdout_cb; void *stdout_data; + char *pipe_stdin; /* runtime data */ pid_t pid; @@ -45,6 +52,7 @@ struct process { /* post-execution information */ int exit_status; + bool cancelled; }; /* Process management system init. process_init must be called before @@ -61,13 +69,24 @@ struct process *process_create(void *ctx); */ void process_release(struct process *process); -/* Synchronous interface. These functions will all block while waiting for - * the process to exit. +/* Synchronous interface. The process_run_sync, process_run_simple and + * process_get_stdout functions will all block while waiting for the child + * process to exit. Calls to the variadic versions must have a NULL terminating + * argument. For the process_get_stdout calls stderr will go to the log. */ int process_run_sync(struct process *process); -int process_run_simple_argv(void *ctx, const char *argv[]); -int process_run_simple(void *ctx, const char *name, ...) - __attribute__((sentinel(0))); +int process_get_stdout_argv(void *ctx, struct process_stdout **stdout, + const char *argv[]); +int process_get_stdout(void *ctx, struct process_stdout **stdout, + const char *path, ...) __attribute__((sentinel(0))); + +static inline int process_run_simple_argv(void *ctx, const char *argv[]) +{ + return process_get_stdout_argv(ctx, NULL, argv); +} +#define process_run_simple(_ctx, _path, args...) \ + process_get_stdout(_ctx, NULL, _path, args) + /* Asynchronous interface. When a process is run with process_run_async, the * function returns without wait()ing for the child process to exit. If the @@ -77,6 +96,7 @@ int process_run_simple(void *ctx, const char *name, ...) int process_run_async(struct process *process); void process_stop_async(struct process *process); +void process_stop_async_all(void); /* helper function to determine if a process exited cleanly, with a non-zero * exit status */ @@ -84,6 +104,6 @@ bool process_exit_ok(struct process *process); /* Functions to assist callers using a custom stdout callback */ struct process *procinfo_get_process(struct process_info *procinfo); -int process_stdout_custom(struct process_info *procinfo, char **line); +int process_process_stdout(struct process_info *procinfo, char **line); #endif /* PROCESS_H */