Index: python/vte.override
===================================================================
--- python/vte.override	(revision 2023)
+++ python/vte.override	(working copy)
@@ -7,6 +7,7 @@
 #include <pygobject.h>
 #include <gtk/gtk.h>
 #include "../src/vte.h"
+#include "../src/pty.h"
 %%
 modulename vte
 %%
Index: python/vte.defs
===================================================================
--- python/vte.defs	(revision 2023)
+++ python/vte.defs	(working copy)
@@ -32,9 +32,16 @@
   )
 )
 
-
 ;; From ../src/vte.h
 
+(define-function vte_child_setup
+  (c-name "vte_child_setup")
+  (parameters
+    '("int" "slave_fd")
+  )
+  (return-type "none")
+)
+
 (define-function vte_terminal_get_type
   (c-name "vte_terminal_get_type")
   (return-type "GtkType")
Index: src/vte.c
===================================================================
--- src/vte.c	(revision 2023)
+++ src/vte.c	(working copy)
@@ -3057,6 +3057,14 @@
 				       directory, lastlog, utmp, wtmp);
 }
 
+/* This function is meant to be called in a child to set it up for
+   acess to a pseudoterminal, just before execution. */
+void
+vte_child_setup(int slave_fd)
+{
+	vte_pty_child_setup(slave_fd);
+}
+
 /* Handle an EOF from the client. */
 static void
 vte_terminal_eof(GIOChannel *channel, VteTerminal *terminal)
Index: src/vte.h
===================================================================
--- src/vte.h	(revision 2023)
+++ src/vte.h	(working copy)
@@ -197,6 +197,8 @@
 #define VTE_IS_TERMINAL_ANTI_ALIAS(obj)		GTK_CHECK_TYPE((obj),\
 						VTE_TYPE_TERMINAL_ANTI_ALIAS)
 
+void vte_child_setup(int slave_fd);
+
 /* You can get by with just these two functions. */
 GtkWidget *vte_terminal_new(void);
 pid_t vte_terminal_fork_command(VteTerminal *terminal,
Index: src/pty.c
===================================================================
--- src/pty.c	(revision 2023)
+++ src/pty.c	(working copy)
@@ -157,7 +157,7 @@
 	} tty;
 };
 static void
-vte_pty_child_setup (gpointer arg)
+_vte_pty_child_setup (gpointer arg)
 {
 	struct vte_pty_child_setup_data *data = arg;
 	int fd = -1;
@@ -180,14 +180,6 @@
 			"Setting up child pty: name = %s, fd = %d\n",
 				tty ? tty : "(none)", fd);
 
-
-	/* Start a new session and become process-group leader. */
-#if defined(HAVE_SETSID) && defined(HAVE_SETPGID)
-	_vte_debug_print (VTE_DEBUG_PTY, "Starting new session\n");
-	setsid();
-	setpgid(0, 0);
-#endif
-
 	/* Try to reopen the pty to acquire it as our controlling terminal. */
 	if (tty != NULL) {
 		int i = open(tty, O_RDWR);
@@ -202,6 +194,19 @@
 	if (fd == -1)
 		_exit (127);
 
+	vte_pty_child_setup(fd);
+}
+
+void
+vte_pty_child_setup(int fd)
+{
+	/* Start a new session and become process-group leader. */
+#if defined(HAVE_SETSID) && defined(HAVE_SETPGID)
+	_vte_debug_print (VTE_DEBUG_PTY, "Starting new session\n");
+	setsid();
+	setpgid(0, 0);
+#endif
+
 #ifdef TIOCSCTTY
 	/* TIOCSCTTY is defined?  Let's try that, too. */
 	ioctl(fd, TIOCSCTTY, fd);
@@ -347,7 +352,7 @@
 				G_SPAWN_SEARCH_PATH |
 				G_SPAWN_DO_NOT_REAP_CHILD |
 				(argv ? G_SPAWN_FILE_AND_ARGV_ZERO : 0),
-				vte_pty_child_setup, data,
+				_vte_pty_child_setup, data,
 				pid,
 				NULL, NULL, NULL,
 				&local_error);
@@ -363,7 +368,7 @@
 						G_SPAWN_SEARCH_PATH |
 						G_SPAWN_DO_NOT_REAP_CHILD |
 						(argv ? G_SPAWN_FILE_AND_ARGV_ZERO : 0),
-						vte_pty_child_setup, data,
+						_vte_pty_child_setup, data,
 						pid,
 						NULL, NULL, NULL,
 						&local_error);
@@ -391,7 +396,7 @@
 						g_strerror (errno));
 				ret = FALSE;
 			case 0: /* child */
-				vte_pty_child_setup (data);
+				_vte_pty_child_setup (data);
 				break;
 			default: /* parent */
 				break;
Index: src/pty.h
===================================================================
--- src/pty.h	(revision 2023)
+++ src/pty.h	(working copy)
@@ -32,6 +32,8 @@
 		  int columns, int rows,
 		  gboolean lastlog, gboolean utmp, gboolean wtmp);
 
+void vte_pty_child_setup(int slave_fd);
+
 /* Set or read the size of a terminal.  Returns 0 on success, -1 on failure,
  * with errno set to defined return codes from ioctl(). */
 int _vte_pty_get_size(int master, int *columns, int *rows);
