summaryrefslogtreecommitdiffstats
path: root/lib/process/process.h
diff options
context:
space:
mode:
authorGeoff Levand <geoff@infradead.org>2018-08-02 17:29:35 +0000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-08-07 11:30:36 +1000
commit51fb307dfdbb8f238d15520a74e33ef4fea52e4d (patch)
tree1eb41650772538c2a7699bed542bd19e4bfe05b1 /lib/process/process.h
parent214de247193d14a2de014e5e4cad1ab3df956c13 (diff)
downloadtalos-petitboot-51fb307dfdbb8f238d15520a74e33ef4fea52e4d.tar.gz
talos-petitboot-51fb307dfdbb8f238d15520a74e33ef4fea52e4d.zip
lib/process: Add process_get_stdout
Add a new structure 'struct process_stdout' and optional parameter 'stdout' to the process_run_simple functions to allow the caller to get a buffer filled with the stdout from the child process. Rename the process_run_simple functions to process_get_stdout and add wrappers for the old process_run_simple function names. Signed-off-by: Geoff Levand <geoff@infradead.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'lib/process/process.h')
-rw-r--r--lib/process/process.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/process/process.h b/lib/process/process.h
index 003ff8e..9473a0d 100644
--- a/lib/process/process.h
+++ b/lib/process/process.h
@@ -27,6 +27,11 @@ 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;
@@ -63,13 +68,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
OpenPOWER on IntegriCloud