[glib/wip/gsubprocess-2.36: 1/2] wip



commit 06aa27693e5821099ec7c9440e26ef2371c1df99
Author: Colin Walters <walters verbum org>
Date:   Mon Oct 15 14:58:18 2012 -0400

    wip

 gio/gioenums.h    |   16 +++++++---------
 gio/gsubprocess.c |   53 +++++++++++++++++++++++++++++++++++++----------------
 gio/gsubprocess.h |    8 +++-----
 3 files changed, 47 insertions(+), 30 deletions(-)
---
diff --git a/gio/gioenums.h b/gio/gioenums.h
index 88e0c86..4af8e26 100644
--- a/gio/gioenums.h
+++ b/gio/gioenums.h
@@ -1664,15 +1664,13 @@ typedef enum /*< flags >*/ {
 typedef enum {
   G_SUBPROCESS_FLAGS_NONE                = 0,
   G_SUBPROCESS_FLAGS_SEARCH_PATH         = (1u << 0),
-  G_SUBPROCESS_FLAGS_TERM_WITH_PARENT    = (1u << 1),
-  G_SUBPROCESS_FLAGS_NEW_SESSION         = (1u << 2),
-  G_SUBPROCESS_FLAGS_STDIN_PIPE          = (1u << 3),
-  G_SUBPROCESS_FLAGS_STDIN_INHERIT       = (1u << 4),
-  G_SUBPROCESS_FLAGS_STDOUT_PIPE         = (1u << 5),
-  G_SUBPROCESS_FLAGS_STDOUT_SILENCE      = (1u << 6),
-  G_SUBPROCESS_FLAGS_STDERR_PIPE         = (1u << 7),
-  G_SUBPROCESS_FLAGS_STDERR_SILENCE      = (1u << 8),
-  G_SUBPROCESS_FLAGS_STDERR_MERGE        = (1u << 9)
+  G_SUBPROCESS_FLAGS_STDIN_PIPE          = (1u << 1),
+  G_SUBPROCESS_FLAGS_STDIN_INHERIT       = (1u << 2),
+  G_SUBPROCESS_FLAGS_STDOUT_PIPE         = (1u << 3),
+  G_SUBPROCESS_FLAGS_STDOUT_SILENCE      = (1u << 4),
+  G_SUBPROCESS_FLAGS_STDERR_PIPE         = (1u << 4),
+  G_SUBPROCESS_FLAGS_STDERR_SILENCE      = (1u << 5),
+  G_SUBPROCESS_FLAGS_STDERR_MERGE        = (1u << 6)
 } GSubprocessFlags;
 
 G_END_DECLS
diff --git a/gio/gsubprocess.c b/gio/gsubprocess.c
index 0034ea0..3bb6764 100644
--- a/gio/gsubprocess.c
+++ b/gio/gsubprocess.c
@@ -122,6 +122,8 @@ enum
   PROP_STDIN,
   PROP_STDOUT,
   PROP_STDERR,
+  PROP_CHILD_SETUP_FUNC,
+  PROP_CHILD_SETUP_DATA,
   N_PROPS
 };
 
@@ -343,6 +345,28 @@ g_subprocess_class_init (GSubprocessClass *class)
                                                           G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
                                                           G_PARAM_STATIC_STRINGS);
 
+  /**
+   * GSubprocess:child-setup-func:
+   *
+   * Function to call in the context of the child process.
+   *
+   * Since: 2.34
+   */
+  g_subprocess_pspecs[PROP_CHILD_SETUP_FUNC] = g_param_spec_pointer ("child-setup-func", P_("Child Setup"), P_("Function to call in context of child process"),
+								     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+								     G_PARAM_STATIC_STRINGS);
+
+  /**
+   * GSubprocess:child-setup-data:
+   *
+   * User data to pass to child setup function
+   *
+   * Since: 2.34
+   */
+  g_subprocess_pspecs[PROP_CHILD_SETUP_DATA] = g_param_spec_pointer ("child-setup-data", P_("Child Setup Data"), P_("User data to pass to child setup function"),
+								     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+								     G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (gobject_class, N_PROPS, g_subprocess_pspecs);
 }
 
@@ -490,6 +514,8 @@ typedef struct
 {
   gint             fds[3];
   GSubprocessFlags flags;
+  GSpawnChildSetupFunc child_setup_func;
+  gpointer             child_setup_data;
 } ChildData;
 
 static void
@@ -515,13 +541,8 @@ child_setup (gpointer user_data)
         while (result == -1 && errno == EINTR);
       }
 
-  if (child_data->flags & G_SUBPROCESS_FLAGS_TERM_WITH_PARENT)
-    /* XXX linux thing... */;
-
-#ifdef G_OS_UNIX
-  if (child_data->flags & G_SUBPROCESS_FLAGS_NEW_SESSION)
-    setsid ();
-#endif
+  if (child_data->child_setup_func)
+    child_data->child_setup_func (child_data->child_setup_data);
 }
 
 static gboolean
@@ -611,6 +632,8 @@ initable_init (GInitable     *initable,
   spawn_flags |= G_SPAWN_CLOEXEC_PIPES;
 
   child_data.flags = self->flags;
+  child_data.child_setup_func = self->child_setup_func;
+  child_data.child_setup_data = self->child_setup_data;
   success = g_spawn_async_with_pipes (self->cwd, self->argv, self->envp,
                                       spawn_flags,
                                       child_setup, &child_data,
@@ -637,9 +660,11 @@ initable_iface_init (GInitableIface *initable_iface)
 }
 
 /**
- * g_subprocess_new:
+ * g_subprocess_new_simple:
  *
- * Create a new process with the given parameters.
+ * Create a new process.  The provided arguments are a small subset of
+ * the available properties, but this function is still useful in a
+ * variety of simple cases.
  *
  * Returns: (transfer full): A newly created %GSubprocess, or %NULL on error (and @error will be set)
  *
@@ -647,17 +672,13 @@ initable_iface_init (GInitableIface *initable_iface)
  */
 GLIB_AVAILABLE_IN_2_34
 GSubprocess *
-g_subprocess_new (const gchar          *cwd,
-                  const gchar * const  *argv,
-                  const gchar * const  *env,
-                  GSubprocessFlags      flags,
-                  GError              **error)
+g_subprocess_new_simple (const gchar * const  *argv,
+			 GSubprocessFlags      flags,
+			 GError              **error)
 {
   return g_initable_new (G_TYPE_SUBPROCESS,
                          NULL, error,
                          "argv", argv,
-                         "working-directory", cwd,
-                         "environment", env,
                          "flags", flags,
                          NULL);
 }
diff --git a/gio/gsubprocess.h b/gio/gsubprocess.h
index a0a3989..1d2ef37 100644
--- a/gio/gsubprocess.h
+++ b/gio/gsubprocess.h
@@ -41,11 +41,9 @@ GType            g_subprocess_get_type (void) G_GNUC_CONST;
 /**** Creation ****/
 
 GLIB_AVAILABLE_IN_2_34
-GSubprocess *    g_subprocess_new (const gchar           *cwd,
-                                   const gchar * const   *argv,
-                                   const gchar * const   *env,
-                                   GSubprocessFlags       flags,
-                                   GError               **error);
+GSubprocess *    g_subprocess_new_simple (const gchar * const   *argv,
+					  GSubprocessFlags       flags,
+					  GError               **error);
 
 GLIB_AVAILABLE_IN_2_34
 GOutputStream *    g_subprocess_get_stdin_pipe (GSubprocess       *self);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]