]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
signal.c: mark the read and write ends of the signal pipe non-blocking.
authorAndre <maan@p133.(none)>
Fri, 7 Apr 2006 10:57:20 +0000 (12:57 +0200)
committerAndre <maan@p133.(none)>
Fri, 7 Apr 2006 10:57:20 +0000 (12:57 +0200)
signal.c

index 82444cc81b9c1ffa7248e701ad36cd606b8fc877..5f121063c10591731a253fb1f227dd1bb0f29da5 100644 (file)
--- 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);
 }