gmain: Document constraints on waitpid

Applications that use glib should not invoke waitpid with a first
argument that is nonpositive, because when such a waitpid is run in
one thread and glib waits for a subprocess in another, there is a race
condition, and the former waitpid can reap a process that was intended
for the latter.  Mention this in the documentation for
g_child_watch_source_new, and in the diagnostic generated by
g_spawn_sync when its waitpid fails with errno equal to ECHILD.

Signed-off-by: Colin Walters <walters@verbum.org>

http://bugzilla.gnome.org/show_bug.cgi?id=687075
This commit is contained in:
Paul Eggert 2012-10-29 10:19:20 -04:00 committed by Colin Walters
parent cff536c99e
commit 00f4c12bf9
2 changed files with 5 additions and 5 deletions

View File

@ -4639,10 +4639,10 @@ g_unix_signal_handler (int signum)
* source is still active. Typically, you will want to call * source is still active. Typically, you will want to call
* g_spawn_close_pid() in the callback function for the source. * g_spawn_close_pid() in the callback function for the source.
* *
* Note further that using g_child_watch_source_new() is not * Note further that using g_child_watch_source_new() is not
* compatible with calling <literal>waitpid(-1)</literal> in * compatible with calling <literal>waitpid</literal> with a
* the application. Calling waitpid() for individual pids will * nonpositive first argument in the application. Calling waitpid()
* still work fine. * for individual pids will still work fine.
* *
* Return value: the newly-created child watch source * Return value: the newly-created child watch source
* *

View File

@ -415,7 +415,7 @@ g_spawn_sync (const gchar *working_directory,
{ {
if (exit_status) if (exit_status)
{ {
g_warning ("In call to g_spawn_sync(), exit status of a child process was requested but SIGCHLD action was set to SIG_IGN and ECHILD was received by waitpid(), so exit status can't be returned. This is a bug in the program calling g_spawn_sync(); either don't request the exit status, or don't set the SIGCHLD action."); g_warning ("In call to g_spawn_sync(), exit status of a child process was requested but ECHILD was received by waitpid(). Most likely the process is ignoring SIGCHLD, or some other thread is invoking waitpid() with a nonpositive first argument; either behavior can break applications that use g_spawn_sync either directly or indirectly.");
} }
else else
{ {