[vte/vte-next] pty: Fix custom child setup function



commit 3367d211b547b64d86ea947c6515d5e5f90fa5b9
Author: Christian Persch <chpe gnome org>
Date:   Fri Mar 23 02:17:25 2012 +0100

    pty: Fix custom child setup function
    
    Fix passing a custom child setup to vte_terminal_fork_command_full().
    Before, it was impossible to actually make use of this, since there's
    no way to get the VtePty to call vte_pty_child_setup() on. Now, just
    store the extra child setup and call it from vte_pty_child_setup().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=672649

 src/pty.c |   31 +++++++++++++++++++++++++------
 src/vte.c |    2 +-
 2 files changed, 26 insertions(+), 7 deletions(-)
---
diff --git a/src/pty.c b/src/pty.c
index 10f89d8..cfd7cd0 100644
--- a/src/pty.c
+++ b/src/pty.c
@@ -199,6 +199,9 @@ typedef struct {
 		const char *name;
 		int fd;
 	} tty;
+
+	GSpawnChildSetupFunc extra_child_setup;
+	gpointer extra_child_setup_data;
 } VtePtyChildSetupData;
 
 /**
@@ -343,6 +346,11 @@ vte_pty_child_setup (VtePty *pty)
         if (priv->term != NULL) {
                 g_setenv("TERM", priv->term, TRUE);
         }
+
+	/* Finally call an extra child setup */
+	if (data->extra_child_setup) {
+		data->extra_child_setup (data->extra_child_setup_data);
+	}
 }
 
 /* TODO: clean up the spawning
@@ -444,6 +452,8 @@ __vte_pty_spawn (VtePty *pty,
                  GPid *child_pid /* out */,
                  GError **error)
 {
+	VtePtyPrivate *priv = pty->priv;
+        VtePtyChildSetupData *data = &priv->child_setup_data;
 	gboolean ret = TRUE;
         char **envp2;
         gint i;
@@ -471,12 +481,14 @@ __vte_pty_spawn (VtePty *pty,
                             directory ? directory : "(none)");
         }
 
+	data->extra_child_setup = child_setup;
+	data->extra_child_setup_data = child_setup_data;
+
         ret = g_spawn_async_with_pipes(directory,
                                        argv, envp2,
                                        spawn_flags,
-                                       child_setup ? child_setup
-                                                   : (GSpawnChildSetupFunc) vte_pty_child_setup,
-                                       child_setup ? child_setup_data : pty,
+                                       (GSpawnChildSetupFunc) vte_pty_child_setup,
+                                       pty,
                                        child_pid,
                                        NULL, NULL, NULL,
                                        &err);
@@ -488,9 +500,8 @@ __vte_pty_spawn (VtePty *pty,
                 ret = g_spawn_async_with_pipes(NULL,
                                                argv, envp2,
                                                spawn_flags,
-                                               child_setup ? child_setup
-                                                           : (GSpawnChildSetupFunc) vte_pty_child_setup,
-                                               child_setup ? child_setup_data : pty,
+                                               (GSpawnChildSetupFunc) vte_pty_child_setup,
+                                               pty,
                                                child_pid,
                                                NULL, NULL, NULL,
                                                &err);
@@ -498,6 +509,9 @@ __vte_pty_spawn (VtePty *pty,
 
         g_strfreev (envp2);
 
+	data->extra_child_setup = NULL;
+	data->extra_child_setup_data = NULL;
+
         if (ret)
                 return TRUE;
 
@@ -1653,6 +1667,11 @@ vte_pty_error_quark(void)
  * If using g_spawn_async() and friends, you MUST either use
  * vte_pty_child_setup() directly as the child setup function, or call
  * vte_pty_child_setup() from your own child setup function supplied.
+ *
+ * When using vte_terminal_fork_command_full() with a custom child setup
+ * function, vte_pty_child_setup() will be called before the supplied
+ * function; you must not call it again.
+ *
  * Also, you MUST pass the %G_SPAWN_DO_NOT_REAP_CHILD flag.
  *
  * If GNOME PTY Helper is available and
diff --git a/src/vte.c b/src/vte.c
index cef91f7..2c7216b 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -3255,7 +3255,7 @@ vte_get_user_shell (void)
  * @envv: (allow-none) (array zero-terminated=1) (element-type filename): a list of environment
  *   variables to be added to the environment before starting the process, or %NULL
  * @spawn_flags: flags from #GSpawnFlags
- * @child_setup: (allow-none) (scope call): function to run in the child just before exec(), or %NULL
+ * @child_setup: (allow-none) (scope call): an extra child setup function to run in the child just before exec(), or %NULL
  * @child_setup_data: user data for @child_setup
  * @child_pid: (out) (allow-none) (transfer full): a location to store the child PID, or %NULL
  * @cancellable: (allow-none): a #GCancellable, or %NULL



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