cmogstored dev/user discussion/issues/patches/etc
 help / color / mirror / code / Atom feed
* [PATCH] preserve errno when inside sig handler for self-pipe
@ 2015-03-09 21:39 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-03-09 21:39 UTC (permalink / raw)
  To: cmogstored-public; +Cc: Mykola Golub, Steven Stewart-Gallus

We must not clobber errno of the main thread inside signal
handler in case write fails.

This bug only affects systems without epoll_pwait where the
self-pipe is required, so it does not affect modern GNU/Linux
systems; but does affect FreeBSD systems and anybody else
relying on kqueue.

Thanks to Steven Stewart-Gallus for a Ruby bug report which
inspired this fix:

Cc: Mykola Golub <>
Cc: Steven Stewart-Gallus <>
 Steven: just wanted you to know your original bug report
 went a long way :)

 selfwake.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/selfwake.c b/selfwake.c
index 1a6908b..06e9d62 100644
--- a/selfwake.c
+++ b/selfwake.c
@@ -42,8 +42,7 @@ void mog_selfwake_wait(struct mog_fd *mfd)
-/* this is async-signal safe (except in the case of bugs) */
-void mog_selfwake_trigger(struct mog_fd *mfd)
+static void selfwake_trigger(struct mog_fd *mfd)
 	ssize_t w;
@@ -64,6 +63,12 @@ retry:
+/* this is async-signal safe (except in the case of our usage bugs) */
+void mog_selfwake_trigger(struct mog_fd *mfd)
+	PRESERVE_ERRNO(selfwake_trigger(mfd));
 void mog_selfwake_drain(struct mog_fd *mfd)
 	ssize_t r;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-09 21:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-09 21:39 [PATCH] preserve errno when inside sig handler for self-pipe Eric Wong

Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).