From 7bbd4328f6d9e01172aefd982d73466acfcad289 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 5 Oct 2023 09:55:49 -0400 Subject: [PATCH] wakeup: Fix g_wakeup_acknowledge if signal comes in It's not very likely, but there is a small chance that an incoming signal could disturb the non-blocking read calls in g_wakeup_acknowledge, leading to a subsequent spurious wake up. This commit addresses the problem by doing the usual EINTR loop (which is already present on the write side incidentally) --- glib/gwakeup.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/glib/gwakeup.c b/glib/gwakeup.c index fbacab220..6ce401e52 100644 --- a/glib/gwakeup.c +++ b/glib/gwakeup.c @@ -207,20 +207,25 @@ g_wakeup_get_pollfd (GWakeup *wakeup, void g_wakeup_acknowledge (GWakeup *wakeup) { - /* read until it is empty */ + int res; if (wakeup->fds[1] == -1) { uint64_t value; /* eventfd() read resets counter */ - read (wakeup->fds[0], &value, sizeof (value)); + do + res = read (wakeup->fds[0], &value, sizeof (value)); + while (G_UNLIKELY (res == -1 && errno == EINTR)); } else { uint8_t value; - while (read (wakeup->fds[0], &value, sizeof (value)) == sizeof (value)); + /* read until it is empty */ + do + res = read (wakeup->fds[0], &value, sizeof (value)); + while (res == sizeof (value) || G_UNLIKELY (res == -1 && errno == EINTR)); } }