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
This commit is contained in:
Ryan Lortie 2014-12-19 17:05:59 -05:00
parent 671292bbb2
commit 7c70377abf

View File

@ -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 */