summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2012-12-21 11:51:15 -0500
committerColin Walters <walters@verbum.org>2012-12-21 11:51:15 -0500
commitb11ad335f459e3c61b317308da57de441660efd0 (patch)
tree3405ec605fc25a14b9b77f0668a9d1068ce2f01a
parent0734be8c1211ba04ecdd14ff30b6c07dbf3b9a84 (diff)
downloadlibgsystem-b11ad335f459e3c61b317308da57de441660efd0.tar.gz
GSSubprocess: Add new helper API to synchronously spawn
This ends up being used a lot in ostree.
-rw-r--r--gsystem-subprocess.c45
-rw-r--r--gsystem-subprocess.h7
2 files changed, 52 insertions, 0 deletions
diff --git a/gsystem-subprocess.c b/gsystem-subprocess.c
index b1980c0..383e921 100644
--- a/gsystem-subprocess.c
+++ b/gsystem-subprocess.c
@@ -891,3 +891,48 @@ gs_subprocess_new_simple_argv (gchar **argv,
return result;
}
+
+/**
+ * gs_subprocess_simple_run_sync:
+ * @cwd: Current working directory
+ * @stdin_disposition: What to do with standard input
+ * @cancellable: a #GCancellable
+ * @error: a #GError
+ * @first_arg: First argument
+ * @...: Remaining arguments, %NULL terminated
+ *
+ * Run a process synchronously, throw an error if it fails.
+ */
+gboolean
+gs_subprocess_simple_run_sync (const char *cwd,
+ GSSubprocessStreamDisposition stdin_disposition,
+ GCancellable *cancellable,
+ GError **error,
+ const char *first_arg,
+ ...)
+{
+ gboolean ret = FALSE;
+ va_list args;
+ GSSubprocess *proc = NULL;
+ GSSubprocessContext *context = NULL;
+
+ va_start (args, first_arg);
+ context = gs_subprocess_context_newa (first_arg, args);
+ va_end (args);
+ gs_subprocess_context_set_stdin_disposition (context, stdin_disposition);
+ gs_subprocess_context_set_cwd (context, cwd);
+ proc = gs_subprocess_new (context, cancellable, error);
+ if (!proc)
+ goto out;
+
+ if (!gs_subprocess_wait_sync_check (proc, cancellable, error))
+ goto out;
+
+ ret = TRUE;
+ out:
+ if (context)
+ g_object_unref (context);
+ if (proc)
+ g_object_unref (proc);
+ return ret;
+}
diff --git a/gsystem-subprocess.h b/gsystem-subprocess.h
index 7ca6417..cc66978 100644
--- a/gsystem-subprocess.h
+++ b/gsystem-subprocess.h
@@ -84,6 +84,13 @@ GSSubprocess * gs_subprocess_new_simple_argv (char **
GCancellable *cancellable,
GError **error);
+gboolean gs_subprocess_simple_run_sync (const char *cwd,
+ GSSubprocessStreamDisposition stdin_disposition,
+ GCancellable *cancellable,
+ GError **error,
+ const char *first_arg,
+ ...) G_GNUC_NULL_TERMINATED;
+
G_END_DECLS
#endif