From a50db8f0f9fd46211f0dccae287c9f016ae48019 Mon Sep 17 00:00:00 2001 From: Andre Date: Fri, 7 Apr 2006 12:57:20 +0200 Subject: [PATCH] signal.c: mark the read and write ends of the signal pipe non-blocking. --- signal.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/signal.c b/signal.c index 82444cc8..5f121063 100644 --- a/signal.c +++ b/signal.c @@ -24,10 +24,10 @@ static int signal_pipe[2]; /** * initialize the paraslash signal subsystem * - * This function creates a pipe, the signal pipe, to deliver pending signals to - * the application. It should be called during the application's startup part, - * followed by subsequent calls to para_install_sighandler() for each signal - * that should be caught. + * This function creates a pipe, the signal pipe, to deliver pending + * signals to the application (Bernstein's trick). It should be called + * during the application's startup part, followed by subsequent calls + * to para_install_sighandler() for each signal that should be caught. * * para_signal_init() installs a generic signal handler which is used for all * signals simultaneously. When a signal arrives, this generic signal handler @@ -41,8 +41,18 @@ static int signal_pipe[2]; */ int para_signal_init(void) { - if (!pipe(signal_pipe)) - return signal_pipe[0]; + int i; + if (pipe(signal_pipe)) + goto err_out; + for (i = 0; i < 2; i++) { + int fd = signal_pipe[i], flags = fcntl(fd, F_GETFL); + if (flags < 0) + goto err_out; + if (fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK) < 0) + goto err_out; + } + return signal_pipe[0]; +err_out: PARA_EMERG_LOG("%s", "pipe error: Can not setup signal pipe"); exit(EXIT_FAILURE); } -- 2.39.2