From 7c70377abf045ed93e18227e424b473c087f12df Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Fri, 19 Dec 2014 17:05:59 -0500 Subject: [PATCH] gmain: Save errno when handling unix signals Our signal handler calls write() on a pipe or an eventfd in order to deliver the notification. It's unlikely, but this could fail, setting errno. We even check the case that it fails with EINTR. If it does set errno, then it has potentially blown away the value or errno that the preempted code cared about (ie: if the signal arrived shortly after a system call but before errno was checked). Wrap the handler with code to save errno. https://bugzilla.gnome.org/show_bug.cgi?id=741791 --- glib/gmain.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glib/gmain.c b/glib/gmain.c index f1bb25410..401baf031 100644 --- a/glib/gmain.c +++ b/glib/gmain.c @@ -5185,10 +5185,14 @@ g_child_watch_dispatch (GSource *source, static void g_unix_signal_handler (int signum) { + gint saved_errno = errno; + unix_signal_pending[signum] = TRUE; any_unix_signal_pending = TRUE; g_wakeup_signal (glib_worker_context->wakeup); + + errno = saved_errno; } #endif /* !G_OS_WIN32 */