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.
This commit is contained in:
Owen Taylor 2004-03-01 20:47:49 +00:00 committed by Owen Taylor
parent 6c6e41510a
commit 38cbfaeb7a
14 changed files with 182 additions and 24 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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)
{
}

View File

@ -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

View File

@ -86,12 +86,12 @@ get_a_child (gint ttl)
gboolean
child_watch_callback (GPid pid, gint status, gpointer data)
{
#ifndef G_OS_WIN32
g_print ("child %d exited, status %d\n", pid, status);
#else
g_print ("child %p exited, status %d\n", pid, status);
gint ttl = GPOINTER_TO_INT (data);
CloseHandle(pid);
#ifndef G_OS_WIN32
g_print ("child %d (ttl %d) exited, status %d\n", pid, ttl, status);
#else
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);