1 From eb860fd898a6a2bd86c11d245294cd0e8cd4304b Mon Sep 17 00:00:00 2001
2 From: Ryan Lortie <desrt@desrt.ca>
3 Date: Tue, 23 Apr 2013 17:26:48 +0000
4 Subject: Partially revert "Merge waitpid() from g_spawn_sync into gmain()"
6 This partially reverts commit ce0022933c255313e010b27f977f4ae02aad1e7e.
8 It used to be safe to use g_spawn_sync() from processes that had their
9 own SIGCHLD handler because it simply called wait(). When it was
10 changed to depend on the GLib child watching infrastructure this meant
11 that GLib had to own the SIGCHLD handler.
13 This caused hangs in at least Pidgin.
15 The patch contained two other improvements to the child watch code which
16 we want to keep, so only revert the changes to gspawn itself.
18 https://bugzilla.gnome.org/show_bug.cgi?id=698081
20 (limited to 'glib/gspawn.c')
22 diff --git a/glib/gspawn.c b/glib/gspawn.c
23 index 381ed5c..01cedf6 100644
33 #include "gstrfuncs.h"
34 @@ -207,21 +206,6 @@ read_data (GString *str,
44 -on_sync_waitpid (GPid pid,
48 - SyncWaitpidData *data = user_data;
49 - *(data->status_p) = status;
50 - g_main_loop_quit (data->loop);
55 * @working_directory: (allow-none): child's current working directory, or %NULL to inherit parent's
56 @@ -277,7 +261,6 @@ g_spawn_sync (const gchar *working_directory,
57 GString *errstr = NULL;
60 - SyncWaitpidData waitpid_data;
62 g_return_val_if_fail (argv != NULL, FALSE);
63 g_return_val_if_fail (!(flags & G_SPAWN_DO_NOT_REAP_CHILD), FALSE);
64 @@ -410,32 +393,45 @@ g_spawn_sync (const gchar *working_directory,
65 close_and_invalidate (&outpipe);
67 close_and_invalidate (&errpipe);
69 - /* Now create a temporary main context and loop, with just one
70 - * waitpid source. We used to invoke waitpid() directly here, but
71 - * this way we unify with the worker thread in gmain.c.
73 + /* Wait for child to exit, even if we have
77 - GMainContext *context;
81 - context = g_main_context_new ();
82 - loop = g_main_loop_new (context, TRUE);
85 + ret = waitpid (pid, &status, 0);
87 - waitpid_data.loop = loop;
88 - waitpid_data.status_p = &status;
90 - source = g_child_watch_source_new (pid);
91 - g_source_set_callback (source, (GSourceFunc)on_sync_waitpid, &waitpid_data, NULL);
92 - g_source_attach (source, context);
93 - g_source_unref (source);
95 - g_main_loop_run (loop);
100 + else if (errno == ECHILD)
104 + 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.");
108 + /* We don't need the exit status. */
113 + if (!failed) /* avoid error pileups */
117 - g_main_context_unref (context);
118 - g_main_loop_unref (loop);
122 + g_set_error (error,
124 + G_SPAWN_ERROR_READ,
125 + _("Unexpected error in waitpid() (%s)"),
126 + g_strerror (errsv));