From 00f4c12bf97432a50e49749895d2c8174e204907 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 29 Oct 2012 10:19:20 -0400 Subject: [PATCH] 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 http://bugzilla.gnome.org/show_bug.cgi?id=687075 --- glib/gmain.c | 8 ++++---- glib/gspawn.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/glib/gmain.c b/glib/gmain.c index c0c458168..133b0f1ee 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -4639,10 +4639,10 @@ g_unix_signal_handler (int signum) * source is still active. Typically, you will want to call * g_spawn_close_pid() in the callback function for the source. * - * Note further that using g_child_watch_source_new() is not - * compatible with calling waitpid(-1) in - * the application. Calling waitpid() for individual pids will - * still work fine. + * Note further that using g_child_watch_source_new() is not + * compatible with calling waitpid with a + * nonpositive first argument in the application. Calling waitpid() + * for individual pids will still work fine. * * Return value: the newly-created child watch source * diff --git a/glib/gspawn.c b/glib/gspawn.c index 14d1b4ca9..5e4922d76 100644 --- a/glib/gspawn.c +++ b/glib/gspawn.c @@ -415,7 +415,7 @@ g_spawn_sync (const gchar *working_directory, { 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 {