summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2004-03-01 20:47:49 +0000
committerOwen Taylor <otaylor@src.gnome.org>2004-03-01 20:47:49 +0000
commit38cbfaeb7a2ca063ec600de2220ba1c6796647a4 (patch)
tree5c41436a9698760a6fd7984a4639bbe08aa05103
parent6c6e41510ae7586ed34c9a6654a4a32d75ccb948 (diff)
Patch from J. Ali Harlow
Mon Mar 1 15:39:57 2004 Owen Taylor <otaylor@redhat.com> Patch from J. Ali Harlow * configure.in: Use void * not HANDLE for GPid on win32. * glib/gspawn.[ch] glib/gspawn-win32.[ch] glib/glib.def: Add g_spawn_close_pid(). * glib/gspawn.[ch]: Make g_spawn functions take GPid * instead if int * (GPid == int on unix, will produce compile warnings until fixed on Win32.) * tests/child-test.c: Make the test a little more inappropriately verbose. * glib/gmain.c: Add some documentation warnings about not closing @pid while the source is active.
-rw-r--r--ChangeLog19
-rw-r--r--ChangeLog.pre-2-1019
-rw-r--r--ChangeLog.pre-2-1219
-rw-r--r--ChangeLog.pre-2-419
-rw-r--r--ChangeLog.pre-2-619
-rw-r--r--ChangeLog.pre-2-819
-rw-r--r--configure.in2
-rw-r--r--docs/reference/glib/glib-sections.txt1
-rw-r--r--glib/glib.def1
-rw-r--r--glib/gmain.c15
-rw-r--r--glib/gspawn-win32.c19
-rw-r--r--glib/gspawn.c31
-rw-r--r--glib/gspawn.h6
-rw-r--r--tests/child-test.c15
14 files changed, 181 insertions, 23 deletions
diff --git a/ChangeLog b/ChangeLog
index 1a8f6465b..75bca55c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+Mon Mar 1 15:39:57 2004 Owen Taylor <otaylor@redhat.com>
+
+ Patch from J. Ali Harlow
+
+ * configure.in: Use void * not HANDLE for GPid on win32.
+
+ * glib/gspawn.[ch] glib/gspawn-win32.[ch] glib/glib.def:
+ Add g_spawn_close_pid().
+
+ * glib/gspawn.[ch]: Make g_spawn functions take
+ GPid * instead if int * (GPid == int on unix, will
+ produce compile warnings until fixed on Win32.)
+
+ * tests/child-test.c: Make the test a little more
+ inappropriately verbose.
+
+ * glib/gmain.c: Add some documentation warnings about
+ not closing @pid while the source is active.
+
Mon Mar 1 20:32:06 2004 Tim Janik <timj@gtk.org>
* autogen.sh:
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 1a8f6465b..75bca55c0 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,22 @@
+Mon Mar 1 15:39:57 2004 Owen Taylor <otaylor@redhat.com>
+
+ Patch from J. Ali Harlow
+
+ * configure.in: Use void * not HANDLE for GPid on win32.
+
+ * glib/gspawn.[ch] glib/gspawn-win32.[ch] glib/glib.def:
+ Add g_spawn_close_pid().
+
+ * glib/gspawn.[ch]: Make g_spawn functions take
+ GPid * instead if int * (GPid == int on unix, will
+ produce compile warnings until fixed on Win32.)
+
+ * tests/child-test.c: Make the test a little more
+ inappropriately verbose.
+
+ * glib/gmain.c: Add some documentation warnings about
+ not closing @pid while the source is active.
+
Mon Mar 1 20:32:06 2004 Tim Janik <timj@gtk.org>
* autogen.sh:
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index 1a8f6465b..75bca55c0 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,22 @@
+Mon Mar 1 15:39:57 2004 Owen Taylor <otaylor@redhat.com>
+
+ Patch from J. Ali Harlow
+
+ * configure.in: Use void * not HANDLE for GPid on win32.
+
+ * glib/gspawn.[ch] glib/gspawn-win32.[ch] glib/glib.def:
+ Add g_spawn_close_pid().
+
+ * glib/gspawn.[ch]: Make g_spawn functions take
+ GPid * instead if int * (GPid == int on unix, will
+ produce compile warnings until fixed on Win32.)
+
+ * tests/child-test.c: Make the test a little more
+ inappropriately verbose.
+
+ * glib/gmain.c: Add some documentation warnings about
+ not closing @pid while the source is active.
+
Mon Mar 1 20:32:06 2004 Tim Janik <timj@gtk.org>
* autogen.sh:
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 1a8f6465b..75bca55c0 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,22 @@
+Mon Mar 1 15:39:57 2004 Owen Taylor <otaylor@redhat.com>
+
+ Patch from J. Ali Harlow
+
+ * configure.in: Use void * not HANDLE for GPid on win32.
+
+ * glib/gspawn.[ch] glib/gspawn-win32.[ch] glib/glib.def:
+ Add g_spawn_close_pid().
+
+ * glib/gspawn.[ch]: Make g_spawn functions take
+ GPid * instead if int * (GPid == int on unix, will
+ produce compile warnings until fixed on Win32.)
+
+ * tests/child-test.c: Make the test a little more
+ inappropriately verbose.
+
+ * glib/gmain.c: Add some documentation warnings about
+ not closing @pid while the source is active.
+
Mon Mar 1 20:32:06 2004 Tim Janik <timj@gtk.org>
* autogen.sh:
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 1a8f6465b..75bca55c0 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,22 @@
+Mon Mar 1 15:39:57 2004 Owen Taylor <otaylor@redhat.com>
+
+ Patch from J. Ali Harlow
+
+ * configure.in: Use void * not HANDLE for GPid on win32.
+
+ * glib/gspawn.[ch] glib/gspawn-win32.[ch] glib/glib.def:
+ Add g_spawn_close_pid().
+
+ * glib/gspawn.[ch]: Make g_spawn functions take
+ GPid * instead if int * (GPid == int on unix, will
+ produce compile warnings until fixed on Win32.)
+
+ * tests/child-test.c: Make the test a little more
+ inappropriately verbose.
+
+ * glib/gmain.c: Add some documentation warnings about
+ not closing @pid while the source is active.
+
Mon Mar 1 20:32:06 2004 Tim Janik <timj@gtk.org>
* autogen.sh:
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 1a8f6465b..75bca55c0 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,22 @@
+Mon Mar 1 15:39:57 2004 Owen Taylor <otaylor@redhat.com>
+
+ Patch from J. Ali Harlow
+
+ * configure.in: Use void * not HANDLE for GPid on win32.
+
+ * glib/gspawn.[ch] glib/gspawn-win32.[ch] glib/glib.def:
+ Add g_spawn_close_pid().
+
+ * glib/gspawn.[ch]: Make g_spawn functions take
+ GPid * instead if int * (GPid == int on unix, will
+ produce compile warnings until fixed on Win32.)
+
+ * tests/child-test.c: Make the test a little more
+ inappropriately verbose.
+
+ * glib/gmain.c: Add some documentation warnings about
+ not closing @pid while the source is active.
+
Mon Mar 1 20:32:06 2004 Tim Janik <timj@gtk.org>
* autogen.sh:
diff --git a/configure.in b/configure.in
index 625711f90..a629e76dd 100644
--- a/configure.in
+++ b/configure.in
@@ -131,7 +131,7 @@ case "$host" in
GOBJECT_DEF=gobject.def
GTHREAD_DEF=gthread.def
TESTGMODULE_EXP=testgmodule.exp
- glib_pid_type=HANDLE
+ glib_pid_type='void *'
;;
*)
glib_native_win32=no
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 05c6685c3..b75c69ef7 100644
--- a/docs/reference/glib/glib-sections.txt
+++ b/docs/reference/glib/glib-sections.txt
@@ -874,6 +874,7 @@ g_spawn_async
g_spawn_sync
g_spawn_command_line_async
g_spawn_command_line_sync
+g_spawn_close_pid
<SUBSECTION Private>
g_spawn_error_quark
</SECTION>
diff --git a/glib/glib.def b/glib/glib.def
index a41b24a58..7fc4966f9 100644
--- a/glib/glib.def
+++ b/glib/glib.def
@@ -579,6 +579,7 @@ EXPORTS
g_spaced_primes_closest
g_spawn_async
g_spawn_async_with_pipes
+ g_spawn_close_pid
g_spawn_command_line_async
g_spawn_command_line_sync
g_spawn_error_quark
diff --git a/glib/gmain.c b/glib/gmain.c
index 832abc42f..b78842eb4 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -3634,6 +3634,11 @@ g_child_watch_source_init (void)
* and must be added to one with g_source_attach() before it will be
* executed.
*
+ * Note that on platforms where #GPid must be explicitely closed
+ * (see g_spawn_close_pid()) @pid must not be closed while the
+ * source is still active. Typically, you will want to call
+ * g_spawn_close_pid() in the callback function for the source.
+ *
* Return value: the newly-created child watch source
*
* Since: 2.4
@@ -3670,6 +3675,11 @@ g_child_watch_source_new (GPid pid)
* Sets a function to be called when the child indicated by @pid exits, at a
* default priority, #G_PRIORITY_DEFAULT.
*
+ * Note that on platforms where #GPid must be explicitely closed
+ * (see g_spawn_close_pid()) @pid must not be closed while the
+ * source is still active. Typically, you will want to call
+ * g_spawn_close_pid() in the callback function for the source.
+ *
* Return value: the id of event source.
*
* Since: 2.4
@@ -3707,6 +3717,11 @@ g_child_watch_add_full (gint priority,
* Sets a function to be called when the child indicated by @pid exits, at a
* default priority, #G_PRIORITY_DEFAULT.
*
+ * Note that on platforms where #GPid must be explicitely closed
+ * (see g_spawn_close_pid()) @pid must not be closed while the
+ * source is still active. Typically, you will want to call
+ * g_spawn_close_pid() in the callback function for the source.
+ *
* Return value: the id of event source.
*
* Since: 2.4
diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c
index 2ddcdacc6..743ace6f2 100644
--- a/glib/gspawn-win32.c
+++ b/glib/gspawn-win32.c
@@ -202,7 +202,7 @@ static gboolean do_spawn_with_pipes (gboolean dont_wait,
gboolean file_and_argv_zero,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_handle,
+ GPid *child_handle,
gint *standard_input,
gint *standard_output,
gint *standard_error,
@@ -225,7 +225,7 @@ g_spawn_async (const gchar *working_directory,
GSpawnFlags flags,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_handle,
+ GPid *child_handle,
GError **error)
{
g_return_val_if_fail (argv != NULL, FALSE);
@@ -316,7 +316,7 @@ g_spawn_sync (const gchar *working_directory,
{
gint outpipe = -1;
gint errpipe = -1;
- gint pid;
+ GPid pid;
GIOChannel *outchannel = NULL;
GIOChannel *errchannel = NULL;
GPollFD outfd, errfd;
@@ -492,6 +492,8 @@ g_spawn_sync (const gchar *working_directory,
if (errpipe >= 0)
close_and_invalidate (&errpipe);
+ g_spawn_close_pid(pid);
+
if (failed)
{
if (outstr)
@@ -523,7 +525,7 @@ g_spawn_async_with_pipes (const gchar *working_directory,
GSpawnFlags flags,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_handle,
+ GPid *child_handle,
gint *standard_input,
gint *standard_output,
gint *standard_error,
@@ -869,7 +871,7 @@ do_spawn_with_pipes (gboolean dont_wait,
gboolean file_and_argv_zero,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_handle,
+ GPid *child_handle,
gint *standard_input,
gint *standard_output,
gint *standard_error,
@@ -1036,5 +1038,10 @@ make_pipe (gint p[2],
else
return TRUE;
}
-
#endif /* !GSPAWN_HELPER */
+
+void
+g_spawn_close_pid (GPid pid)
+{
+ CloseHandle (pid);
+}
diff --git a/glib/gspawn.c b/glib/gspawn.c
index c56b364a7..d6adcd1f0 100644
--- a/glib/gspawn.c
+++ b/glib/gspawn.c
@@ -58,7 +58,7 @@ static gboolean fork_exec_with_pipes (gboolean intermediate_child,
gboolean file_and_argv_zero,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_pid,
+ GPid *child_pid,
gint *standard_input,
gint *standard_output,
gint *standard_error,
@@ -96,7 +96,7 @@ g_spawn_async (const gchar *working_directory,
GSpawnFlags flags,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_pid,
+ GPid *child_pid,
GError **error)
{
g_return_val_if_fail (argv != NULL, FALSE);
@@ -213,7 +213,7 @@ g_spawn_sync (const gchar *working_directory,
{
gint outpipe = -1;
gint errpipe = -1;
- gint pid;
+ GPid pid;
fd_set fds;
gint ret;
GString *outstr = NULL;
@@ -535,6 +535,9 @@ g_spawn_sync (const gchar *working_directory,
*
* If an error occurs, @child_pid, @standard_input, @standard_output,
* and @standard_error will not be filled with valid values.
+ *
+ * If @child_pid is not %NULL and an error does not occur then the returned
+ * pid must be closed using g_spawn_close_pid().
*
* Return value: %TRUE on success, %FALSE if an error was set
**/
@@ -545,7 +548,7 @@ g_spawn_async_with_pipes (const gchar *working_directory,
GSpawnFlags flags,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_pid,
+ GPid *child_pid,
gint *standard_input,
gint *standard_output,
gint *standard_error,
@@ -1024,13 +1027,13 @@ fork_exec_with_pipes (gboolean intermediate_child,
gboolean file_and_argv_zero,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_pid,
+ GPid *child_pid,
gint *standard_input,
gint *standard_output,
gint *standard_error,
GError **error)
{
- gint pid = -1;
+ GPid pid = -1;
gint stdin_pipe[2] = { -1, -1 };
gint stdout_pipe[2] = { -1, -1 };
gint stderr_pipe[2] = { -1, -1 };
@@ -1093,7 +1096,7 @@ fork_exec_with_pipes (gboolean intermediate_child,
* is to exit, so we can waitpid() it immediately.
* Then the grandchild will not become a zombie.
*/
- gint grandchild_pid;
+ GPid grandchild_pid;
grandchild_pid = fork ();
@@ -1517,3 +1520,17 @@ g_execute (const gchar *file,
/* Return the error from the last attempt (probably ENOENT). */
return -1;
}
+
+/**
+ * g_spawn_close_pid:
+ * @pid: The process identifier to close
+ *
+ * On some platforms, notably WIN32, the #GPid type represents a resource
+ * which must be closed to prevent resource leaking. g_spawn_close_pid()
+ * is provided for this purpose. It should be used on all platforms, even
+ * though it doesn't do anything under UNIX.
+ **/
+void
+g_spawn_close_pid (GPid pid)
+{
+}
diff --git a/glib/gspawn.h b/glib/gspawn.h
index 795bb3ce6..9ca187946 100644
--- a/glib/gspawn.h
+++ b/glib/gspawn.h
@@ -77,7 +77,7 @@ gboolean g_spawn_async (const gchar *working_directory,
GSpawnFlags flags,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_pid,
+ GPid *child_pid,
GError **error);
@@ -90,7 +90,7 @@ gboolean g_spawn_async_with_pipes (const gchar *working_directory,
GSpawnFlags flags,
GSpawnChildSetupFunc child_setup,
gpointer user_data,
- gint *child_pid,
+ GPid *child_pid,
gint *standard_input,
gint *standard_output,
gint *standard_error,
@@ -120,6 +120,8 @@ gboolean g_spawn_command_line_sync (const gchar *command_line,
gboolean g_spawn_command_line_async (const gchar *command_line,
GError **error);
+void g_spawn_close_pid (GPid pid);
+
G_END_DECLS
diff --git a/tests/child-test.c b/tests/child-test.c
index 3d36774f3..09263e948 100644
--- a/tests/child-test.c
+++ b/tests/child-test.c
@@ -86,12 +86,12 @@ get_a_child (gint ttl)
gboolean
child_watch_callback (GPid pid, gint status, gpointer data)
{
+ gint ttl = GPOINTER_TO_INT (data);
+
#ifndef G_OS_WIN32
- g_print ("child %d exited, status %d\n", pid, status);
+ g_print ("child %d (ttl %d) exited, status %d\n", pid, ttl, status);
#else
- g_print ("child %p exited, status %d\n", pid, status);
-
- CloseHandle(pid);
+ g_print ("child %p (ttl %d) exited, status %d\n", pid, ttl, status);
#endif
if (--alive == 0)
@@ -112,14 +112,15 @@ test_thread (gpointer data)
pid = get_a_child (ttl);
source = g_child_watch_source_new (pid);
- g_source_set_callback (source, (GSourceFunc) child_watch_callback, NULL, NULL);
+ g_source_set_callback (source, (GSourceFunc) child_watch_callback, data, NULL);
g_source_attach (source, g_main_loop_get_context (new_main_loop));
g_source_unref (source);
#ifdef G_OS_WIN32
- g_print ("whee! created pid: %p\n", pid);
+ g_print ("whee! created pid: %p (ttl %d)\n", pid, ttl);
+ CloseHandle(pid);
#else
- g_print ("whee! created pid: %d\n", pid);
+ g_print ("whee! created pid: %d (ttl %d)\n", pid, ttl);
#endif
g_main_loop_run (new_main_loop);