[glib] gmain: Save errno when handling unix signals
- From: Ryan Lortie <desrt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gmain: Save errno when handling unix signals
- Date: Fri, 20 Mar 2015 17:33:00 +0000 (UTC)
commit 7c70377abf045ed93e18227e424b473c087f12df
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Dec 19 17:05:59 2014 -0500
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 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index f1bb254..401baf0 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 */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]