summaryrefslogtreecommitdiff
path: root/glib
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 /glib
parent6c6e41510ae7586ed34c9a6654a4a32d75ccb948 (diff)
downloadglib-38cbfaeb7a2ca063ec600de2220ba1c6796647a4.tar.gz
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.
Diffstat (limited to 'glib')
-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
5 files changed, 57 insertions, 15 deletions
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