summaryrefslogtreecommitdiffstats
path: root/lib/process/process.h
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-08-12 15:57:41 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-08-19 13:27:59 +0800
commite52a8c61a640ab4fce0b4caaa796ae3e1c4ff8a3 (patch)
tree2256e91d0b24e068531361a8b0793cd2be3832fc /lib/process/process.h
parente25ee629c6dfa47c13121cc70b2da1b2dd21036c (diff)
downloadtalos-petitboot-e52a8c61a640ab4fce0b4caaa796ae3e1c4ff8a3.tar.gz
talos-petitboot-e52a8c61a640ab4fce0b4caaa796ae3e1c4ff8a3.zip
lib/process: Add process helpers
We've grown-out of pb_run_cmd a little, as we have a number of different process types: boot(): - kexec: short-running process, run synchronously - boot hooks: short-running, run sync, need exit code & stdout network init: - interface configuration: short running, run sync - udhcp processes are long running, we may want completion, but doesn't block other actions downloads: - potentially long-running, block parse progress config nvram: - read: short running, can block, need stdout - write: short running, can block We'd like to introduce proper asynchronous processes, to allow config & boot-option downloads without blocking the discover server. This change introduces a new type for processes, 'struct process'. These structures are created with process_create, and run with process_run_sync or process_run_async. The latter reports completion through a callback member of struct process. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'lib/process/process.h')
-rw-r--r--lib/process/process.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/process/process.h b/lib/process/process.h
new file mode 100644
index 0000000..9e2a2d1
--- /dev/null
+++ b/lib/process/process.h
@@ -0,0 +1,76 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef PROCESS_H
+#define PROCESS_H
+
+#include <stdbool.h>
+#include <sys/types.h>
+
+#include <list/list.h>
+#include <waiter/waiter.h>
+
+struct process;
+struct procset;
+
+typedef void (*process_exit_cb)(struct process *);
+
+struct process {
+ /* caller-provided configuration */
+ const char *path;
+ const char **argv;
+ bool keep_stdout;
+ process_exit_cb exit_cb;
+ void *data;
+
+ /* runtime data */
+ pid_t pid;
+ int stdout_len;
+ char *stdout_buf;
+
+ /* post-execution information */
+ int exit_status;
+};
+
+/* Process management system init. process_init must be called before
+ * process_create. The pointer returned can be talloc_free()-ed, or can be
+ * automatically freed through destruction of the ctx talloc tree.
+ */
+struct procset *process_init(void *ctx, struct waitset *set);
+
+struct process *process_create(void *ctx);
+
+/* process_release: release our reference to the process, but potentially
+ * leave it running. When the process exits, associated resources will
+ * be deallocated.
+ */
+void process_release(struct process *process);
+
+/* Synchronous interface. These functions will all block while waiting for
+ * the process to exit.
+ */
+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)));
+
+/* 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
+ * process' exit_cb member is set, that callback will be invoked when the
+ * process exits.
+ */
+int process_run_async(struct process *process);
+
+void process_stop_async(struct process *process);
+#endif /* PROCESS_H */
OpenPOWER on IntegriCloud