[libgsystem] GSSubprocess: Add new helper API to synchronously spawn
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsystem] GSSubprocess: Add new helper API to synchronously spawn
- Date: Fri, 21 Dec 2012 19:15:13 +0000 (UTC)
commit b11ad335f459e3c61b317308da57de441660efd0
Author: Colin Walters <walters verbum org>
Date: Fri Dec 21 11:51:15 2012 -0500
GSSubprocess: Add new helper API to synchronously spawn
This ends up being used a lot in ostree.
gsystem-subprocess.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
gsystem-subprocess.h | 7 +++++++
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]