From a79b8073aae24c2d6b191fb3bb5ba5506d3bd8b0 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 18 Nov 2002 09:58:39 +0000 Subject: [PATCH] Do handle G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If 2002-11-18 Tor Lillqvist * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the flag is not set, don't call DuplicateHandle() on the handle returned by the helper process, and set the "child pid" returned to the caller to zero. Close the handle to the helper process in all cases. * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows behaviour of G_SPAWN_DO_NOT_REAP_CHILD. --- ChangeLog | 12 ++++++++++++ ChangeLog.pre-2-10 | 12 ++++++++++++ ChangeLog.pre-2-12 | 12 ++++++++++++ ChangeLog.pre-2-2 | 12 ++++++++++++ ChangeLog.pre-2-4 | 12 ++++++++++++ ChangeLog.pre-2-6 | 12 ++++++++++++ ChangeLog.pre-2-8 | 12 ++++++++++++ glib/gspawn-win32.c | 7 ++++++- glib/gspawn.c | 29 +++++++++++++++++++++-------- 9 files changed, 111 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3da17ffc6..cf9e1db96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2002-11-18 Tor Lillqvist + + * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle + G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the + flag is not set, don't call DuplicateHandle() on the handle + returned by the helper process, and set the "child pid" returned + to the called to zero. Close the handle to the helper process in + all cases. + + * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows + behaviour of G_SPAWN_DO_NOT_REAP_CHILD. + 2002-11-18 Tor Lillqvist [Win32] Fix the asynchronous g_spawn* to return the process handle diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 3da17ffc6..cf9e1db96 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,15 @@ +2002-11-18 Tor Lillqvist + + * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle + G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the + flag is not set, don't call DuplicateHandle() on the handle + returned by the helper process, and set the "child pid" returned + to the called to zero. Close the handle to the helper process in + all cases. + + * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows + behaviour of G_SPAWN_DO_NOT_REAP_CHILD. + 2002-11-18 Tor Lillqvist [Win32] Fix the asynchronous g_spawn* to return the process handle diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 3da17ffc6..cf9e1db96 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,15 @@ +2002-11-18 Tor Lillqvist + + * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle + G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the + flag is not set, don't call DuplicateHandle() on the handle + returned by the helper process, and set the "child pid" returned + to the called to zero. Close the handle to the helper process in + all cases. + + * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows + behaviour of G_SPAWN_DO_NOT_REAP_CHILD. + 2002-11-18 Tor Lillqvist [Win32] Fix the asynchronous g_spawn* to return the process handle diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 3da17ffc6..cf9e1db96 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,15 @@ +2002-11-18 Tor Lillqvist + + * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle + G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the + flag is not set, don't call DuplicateHandle() on the handle + returned by the helper process, and set the "child pid" returned + to the called to zero. Close the handle to the helper process in + all cases. + + * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows + behaviour of G_SPAWN_DO_NOT_REAP_CHILD. + 2002-11-18 Tor Lillqvist [Win32] Fix the asynchronous g_spawn* to return the process handle diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 3da17ffc6..cf9e1db96 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,15 @@ +2002-11-18 Tor Lillqvist + + * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle + G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the + flag is not set, don't call DuplicateHandle() on the handle + returned by the helper process, and set the "child pid" returned + to the called to zero. Close the handle to the helper process in + all cases. + + * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows + behaviour of G_SPAWN_DO_NOT_REAP_CHILD. + 2002-11-18 Tor Lillqvist [Win32] Fix the asynchronous g_spawn* to return the process handle diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 3da17ffc6..cf9e1db96 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,15 @@ +2002-11-18 Tor Lillqvist + + * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle + G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the + flag is not set, don't call DuplicateHandle() on the handle + returned by the helper process, and set the "child pid" returned + to the called to zero. Close the handle to the helper process in + all cases. + + * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows + behaviour of G_SPAWN_DO_NOT_REAP_CHILD. + 2002-11-18 Tor Lillqvist [Win32] Fix the asynchronous g_spawn* to return the process handle diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 3da17ffc6..cf9e1db96 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,15 @@ +2002-11-18 Tor Lillqvist + + * glib/gspawn-win32.c (do_spawn_with_pipes): Do handle + G_SPAWN_DO_NOT_REAP_CHILD after all, similarily as on Unix. If the + flag is not set, don't call DuplicateHandle() on the handle + returned by the helper process, and set the "child pid" returned + to the called to zero. Close the handle to the helper process in + all cases. + + * glib/gspawn.c (g_spawn_async_with_pipes): Document Windows + behaviour of G_SPAWN_DO_NOT_REAP_CHILD. + 2002-11-18 Tor Lillqvist [Win32] Fix the asynchronous g_spawn* to return the process handle diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index 1ffecffbf..8222fefb1 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -99,6 +99,7 @@ enum { static gboolean make_pipe (gint p[2], GError **error); static gboolean do_spawn_with_pipes (gboolean dont_wait, + gboolean dont_return_handle, const gchar *working_directory, gchar **argv, gchar **envp, @@ -254,6 +255,7 @@ g_spawn_sync (const gchar *working_directory, *standard_error = NULL; if (!do_spawn_with_pipes (FALSE, + TRUE, working_directory, argv, envp, @@ -444,6 +446,7 @@ g_spawn_async_with_pipes (const gchar *working_directory, !(flags & G_SPAWN_CHILD_INHERITS_STDIN), FALSE); return do_spawn_with_pipes (TRUE, + !(flags & G_SPAWN_DO_NOT_REAP_CHILD), working_directory, argv, envp, @@ -714,6 +717,7 @@ read_ints (int fd, static gboolean do_spawn_with_pipes (gboolean dont_wait, + gboolean dont_return_handle, const gchar *working_directory, gchar **argv, gchar **envp, @@ -787,7 +791,7 @@ do_spawn_with_pipes (gboolean dont_wait, switch (buf[0]) { case CHILD_NO_ERROR: - if (child_pid && dont_wait) + if (child_pid && dont_wait && !dont_return_handle) { /* helper is our HANDLE for gspawn-win32-helper. It has * told us the HANDLE of its child. Duplicate that into @@ -830,6 +834,7 @@ do_spawn_with_pipes (gboolean dont_wait, *standard_error = stderr_pipe[0]; if (exit_status) *exit_status = buf[1]; + CloseHandle ((HANDLE) helper); return TRUE; diff --git a/glib/gspawn.c b/glib/gspawn.c index de353ac9d..b360871db 100644 --- a/glib/gspawn.c +++ b/glib/gspawn.c @@ -437,10 +437,16 @@ g_spawn_sync (const gchar *working_directory, * parent's environment. * * @flags should be the bitwise OR of any flags you want to affect the - * function's behavior. The %G_SPAWN_DO_NOT_REAP_CHILD means that the - * child will not be automatically reaped; you must call - * waitpid() or handle %SIGCHLD yourself, or the - * child will become a zombie. + * function's behavior. On Unix, the %G_SPAWN_DO_NOT_REAP_CHILD means + * that the child will not be automatically reaped; you must call + * waitpid() or handle %SIGCHLD yourself, or the + * child will become a zombie. On Windows, the flag means that a + * handle to the child will be returned @child_pid. You must call + * CloseHandle() on it eventually (or exit the + * process), or the child processs will continue to take up some table + * space even after its death. Quite similar to zombies on Unix, + * actually. + * * %G_SPAWN_LEAVE_DESCRIPTORS_OPEN means that the parent's open file * descriptors will be inherited by the child; otherwise all * descriptors except stdin/stdout/stderr will be closed before @@ -477,10 +483,17 @@ g_spawn_sync (const gchar *working_directory, * process. You should carefully consider what you do in @child_setup * if you intend your software to be portable to Windows. * - * If non-%NULL, @child_pid will be filled with the child's process - * ID. You can use the process ID to send signals to the child, or - * to waitpid() if you specified the - * %G_SPAWN_DO_NOT_REAP_CHILD flag. + * If non-%NULL, @child_pid will on Unix be filled with the child's + * process ID. You can use the process ID to send signals to the + * child, or to waitpid() if you specified the + * %G_SPAWN_DO_NOT_REAP_CHILD flag. On Windows, @child_pid will be + * filled with a handle to the child process only if you specified the + * %G_SPAWN_DO_NOT_REAP_CHILD flag. You can then access the child + * process using the Win32 API, for example wait for its termination + * with the WaitFor*() functions, or examine its + * exit code with GetExitCodeProcess(). You + * should close the handle with CloseHandle() + * when you no longer need it. * * If non-%NULL, the @standard_input, @standard_output, @standard_error * locations will be filled with file descriptors for writing to the child's