[glib/wip/gsubprocess] GSubprocess: [rebase] Change stdin API to _inherit()
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/gsubprocess] GSubprocess: [rebase] Change stdin API to _inherit()
- Date: Mon, 11 Jun 2012 21:16:49 +0000 (UTC)
commit 9cbf92405e66f27fa64912f567e520fbff5c5c8f
Author: Colin Walters <walters verbum org>
Date: Mon Jun 11 17:16:13 2012 -0400
GSubprocess: [rebase] Change stdin API to _inherit()
gio/gsubprocess.c | 57 ++++++++++++++++------------------------------
gio/gsubprocess.h | 4 +-
gio/tests/gsubprocess.c | 20 +++++++++++++++-
3 files changed, 41 insertions(+), 40 deletions(-)
---
diff --git a/gio/gsubprocess.c b/gio/gsubprocess.c
index e804421..7aef2d0 100644
--- a/gio/gsubprocess.c
+++ b/gio/gsubprocess.c
@@ -73,7 +73,7 @@ struct _GSubprocess
guint search_path : 1;
guint search_path_from_envp : 1;
guint leave_descriptors_open : 1;
- guint stdin_to_devnull : 1;
+ guint stdin_inherit : 1;
guint stdout_to_devnull : 1;
guint stderr_to_devnull : 1;
guint stderr_to_stdout : 1;
@@ -122,7 +122,7 @@ g_subprocess_init (GSubprocess *self)
{
self->state = G_SUBPROCESS_STATE_BUILDING;
self->child_argv = g_ptr_array_new_with_free_func (g_free);
- self->stdin_to_devnull = TRUE;
+ self->stdin_inherit = FALSE;
self->stdin_fd = -1;
self->internal_stdin_fd = -1;
self->stdout_fd = -1;
@@ -787,7 +787,7 @@ g_subprocess_set_child_setup (GSubprocess *self,
* other related functions such as
* g_subprocess_set_standard_input_unix_fd(),
* g_subprocess_set_standard_input_stream(), and
- * g_subprocess_set_standard_input_to_devnull().
+ * g_subprocess_set_standard_input_inherit().
*
* It is invalid to call this function after g_subprocess_start() has
* been called.
@@ -804,7 +804,7 @@ g_subprocess_set_standard_input_file_path (GSubprocess *self,
g_clear_object (&self->stdin_stream);
g_clear_pointer (&self->stdin_path, g_free);
- self->stdin_to_devnull = FALSE;
+ self->stdin_inherit = FALSE;
self->stdin_fd = -1;
self->stdin_path = g_strdup (file_path);
@@ -837,7 +837,7 @@ g_subprocess_set_standard_input_unix_fd (GSubprocess *self,
g_clear_object (&self->stdin_stream);
g_clear_pointer (&self->stdin_path, g_free);
- self->stdin_to_devnull = FALSE;
+ self->stdin_inherit = FALSE;
self->stdin_fd = -1;
self->stdin_fd = fd;
@@ -845,9 +845,9 @@ g_subprocess_set_standard_input_unix_fd (GSubprocess *self,
#endif
/**
- * g_subprocess_set_standard_input_to_devnull:
+ * g_subprocess_set_standard_input_inherit:
* @self: a #GSubprocess
- * @to_devnull: If %TRUE, redirect input from null stream, if %FALSE, inherit
+ * @inherit: If %TRUE, redirect input from null stream, if %FALSE, inherit
*
* The default is for child processes to have their input stream
* pointed at a null stream (e.g. on Unix, /dev/null), because having
@@ -855,8 +855,8 @@ g_subprocess_set_standard_input_unix_fd (GSubprocess *self,
* conditions and is generally nonsensical. See the documentation of
* g_spawn_async_with_pipes() and %G_SPAWN_CHILD_INHERITS_STDIN.
*
- * If @to_devnull is %FALSE, then this function will cause the
- * standard input of the child process to be inherited.
+ * If @inherit is %TRUE, then this function will cause the standard
+ * input of the child process to be inherited.
*
* Calling this function overrides any previous calls, as well as
* other related functions such as
@@ -868,18 +868,18 @@ g_subprocess_set_standard_input_unix_fd (GSubprocess *self,
* Since: 2.34
*/
void
-g_subprocess_set_standard_input_to_devnull (GSubprocess *self,
- gboolean to_devnull)
+g_subprocess_set_standard_input_inherit (GSubprocess *self,
+ gboolean inherit)
{
g_return_if_fail (G_IS_SUBPROCESS (self));
g_return_if_fail (self->state == G_SUBPROCESS_STATE_BUILDING);
g_clear_object (&self->stdin_stream);
g_clear_pointer (&self->stdin_path, g_free);
- self->stdin_to_devnull = FALSE;
+ self->stdin_inherit = FALSE;
self->stdin_fd = -1;
- self->stdin_to_devnull = to_devnull;
+ self->stdin_inherit = inherit;
}
/**
@@ -929,7 +929,7 @@ g_subprocess_set_standard_input_stream (GSubprocess *self,
g_clear_object (&self->stdin_stream);
g_clear_pointer (&self->stdin_path, g_free);
- self->stdin_to_devnull = FALSE;
+ self->stdin_inherit = FALSE;
self->stdin_fd = -1;
self->stdin_stream = g_object_ref (stream);
@@ -1497,35 +1497,18 @@ g_subprocess_start_with_pipes (GSubprocess *self,
if (out_stdin_stream != NULL
|| self->stdin_stream != NULL)
stdin_arg = &stdin_pipe_fd;
- else
- {
- g_assert (self->stdin_fd != -1 || self->stdin_to_devnull);
- stdin_arg = NULL;
- if (!self->stdin_to_devnull)
- spawn_flags |= G_SPAWN_CHILD_INHERITS_STDIN;
- }
+ else if (self->stdin_inherit)
+ spawn_flags |= G_SPAWN_CHILD_INHERITS_STDIN;
if (out_stdout_stream != NULL)
stdout_arg = &stdout_pipe_fd;
- else
- {
- g_assert (self->stdout_fd == -1 || self->stdout_to_devnull);
- stdout_arg = NULL;
- if (self->stdout_to_devnull)
- spawn_flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
- }
+ else if (self->stdout_to_devnull)
+ spawn_flags |= G_SPAWN_STDOUT_TO_DEV_NULL;
if (out_stderr_stream != NULL)
stderr_arg = &stderr_pipe_fd;
- else
- {
- g_assert (self->stderr_fd == -1
- || self->stderr_to_devnull
- || self->stderr_to_stdout);
- stderr_arg = NULL;
- if (self->stderr_to_devnull)
- spawn_flags |= G_SPAWN_STDERR_TO_DEV_NULL;
- }
+ else if (self->stderr_to_devnull)
+ spawn_flags |= G_SPAWN_STDERR_TO_DEV_NULL;
if (!g_spawn_async_with_pipes (self->working_directory,
real_argv,
diff --git a/gio/gsubprocess.h b/gio/gsubprocess.h
index b48af07..329ee1e 100644
--- a/gio/gsubprocess.h
+++ b/gio/gsubprocess.h
@@ -124,8 +124,8 @@ void g_subprocess_set_standard_input_unix_fd (GSubprocess *sel
#endif
GLIB_AVAILABLE_IN_2_34
-void g_subprocess_set_standard_input_to_devnull (GSubprocess *self,
- gboolean to_devnull);
+void g_subprocess_set_standard_input_inherit (GSubprocess *self,
+ gboolean inherit);
GLIB_AVAILABLE_IN_2_34
void g_subprocess_set_standard_input_stream (GSubprocess *self,
diff --git a/gio/tests/gsubprocess.c b/gio/tests/gsubprocess.c
index 66ae52a..68d8c35 100644
--- a/gio/tests/gsubprocess.c
+++ b/gio/tests/gsubprocess.c
@@ -53,7 +53,7 @@ test_noop_all_to_null (void)
proc = get_test_subprocess ("noop");
- g_subprocess_set_standard_input_to_devnull (proc, TRUE);
+ g_subprocess_set_standard_input_inherit (proc, FALSE);
g_subprocess_set_standard_output_to_devnull (proc, TRUE);
g_subprocess_set_standard_error_to_devnull (proc, TRUE);
@@ -95,6 +95,23 @@ test_noop_non_detached (void)
g_object_unref (proc);
}
+static void
+test_noop_stdin_inherit (void)
+{
+ GError *local_error = NULL;
+ GError **error = &local_error;
+ GSubprocess *proc;
+
+ proc = get_test_subprocess ("noop");
+
+ g_subprocess_set_standard_input_inherit (proc, TRUE);
+
+ (void)g_subprocess_start (proc, NULL, error);
+ g_assert_no_error (local_error);
+
+ g_object_unref (proc);
+}
+
#ifdef G_OS_UNIX
static void
@@ -471,6 +488,7 @@ main (int argc, char **argv)
g_test_add_func ("/gsubprocess/noop-all-to-null", test_noop_all_to_null);
g_test_add_func ("/gsubprocess/noop-detached", test_noop_detached);
g_test_add_func ("/gsubprocess/noop-nondetached", test_noop_non_detached);
+ g_test_add_func ("/gsubprocess/noop-stdin-inherit", test_noop_stdin_inherit);
#ifdef G_OS_UNIX
g_test_add_func ("/gsubprocess/search-path", test_search_path);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]