parlib: add a helper to run a process and wait

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/user/parlib/include/parlib/parlib.h b/user/parlib/include/parlib/parlib.h
index d7c0727..aecdb28 100644
--- a/user/parlib/include/parlib/parlib.h
+++ b/user/parlib/include/parlib/parlib.h
@@ -74,6 +74,7 @@
 pid_t create_child_with_stdfds(const char *exe, int argc, char *const argv[],
                                char *const envp[]);
 int provision_core_set(pid_t pid, const struct core_set *cores);
+int run_and_wait(const char *exe, int argc, char *const argv[]);
 
 /* Debugging */
 void set_notify_9(void (*handler)(struct event_msg *ev_msg,
diff --git a/user/parlib/parlib.c b/user/parlib/parlib.c
index 33bead9..01b137d 100644
--- a/user/parlib/parlib.c
+++ b/user/parlib/parlib.c
@@ -7,6 +7,7 @@
 #include <parlib/ros_debug.h>
 #include <parlib/event.h>
 #include <stdlib.h>
+#include <sys/wait.h>
 
 /* Control variables */
 bool parlib_wants_to_be_mcp = TRUE;
@@ -93,6 +94,23 @@
 	return kid;
 }
 
+/* Helper for kicking off a process, but with little specific error handling */
+int run_and_wait(const char *exe, int argc, char *const argv[])
+{
+	extern char **environ;
+
+	pid_t kid;
+
+	kid = create_child_with_stdfds(exe, argc, argv, environ);
+	if (kid < 0)
+		return -1;
+	if (sys_proc_run(kid) < 0)
+		return -1;
+	if (waitpid(kid, NULL, 0) != kid)
+		return -1;
+	return 0;
+}
+
 /* Provisions the CG cores to PID.  Returns -1 if any of them fail. */
 int provision_core_set(pid_t pid, const struct core_set *cores)
 {