From 52b8b9a8b92c88c06669b58dbe016efb94f192de Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 9 Jan 2018 10:36:51 -0500 Subject: [PATCH] unix: use SA_RESTART when setting our sighandler BSD `signal(2)` semantics make some system calls (e.g. for `write`) restartable when interrupted by a signal handler. Use `SA_RESTART` to enable these semantics everywhere that supports them. This was done by libev back when we used it. In addition to being common practice, this is required by C++ stream libraries that interpret `EINTR` as any other error, set `badbit`, and stop writing. I've observed this with `libstdc++` during a `std::cout.flush()` call interrupted by `SIGCHLD`. PR-URL: https://github.com/libuv/libuv/pull/1696 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Santiago Gimeno --- src/unix/signal.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/unix/signal.c b/src/unix/signal.c index cb09ead5..37597780 100644 --- a/src/unix/signal.c +++ b/src/unix/signal.c @@ -28,6 +28,9 @@ #include #include +#ifndef SA_RESTART +# define SA_RESTART 0 +#endif typedef struct { uv_signal_t* handle; @@ -216,7 +219,9 @@ static int uv__signal_register_handler(int signum, int oneshot) { if (sigfillset(&sa.sa_mask)) abort(); sa.sa_handler = uv__signal_handler; - sa.sa_flags = oneshot ? SA_RESETHAND : 0; + sa.sa_flags = SA_RESTART; + if (oneshot) + sa.sa_flags |= SA_RESETHAND; /* XXX save old action so we can restore it later on? */ if (sigaction(signum, &sa, NULL))