fuse_signals.c: use new do_nothing function instead of SIG_IGN
authorNikolaus Rath <Nikolaus@rath.org>
Wed, 24 May 2017 22:56:41 +0000 (15:56 -0700)
committerNikolaus Rath <Nikolaus@rath.org>
Wed, 24 May 2017 22:58:30 +0000 (15:58 -0700)
Fixes: #160.
ChangeLog.rst
lib/fuse_signals.c

index 2b119a99d36bd0384b790a076060e2d9140219f7..3bf56b7dd7349d44bab8e1194571d0bc46bff612 100644 (file)
@@ -1,3 +1,9 @@
+Unreleased Changes
+==================
+
+* `fuse_main()` / `fuse_remove_signal_handlers()`: do not reset
+  `SIGPIPE` handler to `SIG_DFL` it was not set by us.
+
 libfuse 3.0.2 (2017-05-24)
 ==========================
 
index a1bf1d5b1be765d8fe1a4e5d3054084857a56cca..db059e17d2b0b1e74ea89df1eb53fff3f90fc5e6 100644 (file)
@@ -32,6 +32,11 @@ static void exit_handler(int sig)
        }
 }
 
+static void do_nothing(int sig)
+{
+       (void) sig;
+}
+
 static int set_one_signal_handler(int sig, void (*handler)(int), int remove)
 {
        struct sigaction sa;
@@ -57,10 +62,15 @@ static int set_one_signal_handler(int sig, void (*handler)(int), int remove)
 
 int fuse_set_signal_handlers(struct fuse_session *se)
 {
+       /* If we used SIG_IGN instead of the do_nothing function,
+          then we would be unable to tell if we set SIG_IGN (and
+          thus should reset to SIG_DFL in fuse_remove_signal_handlers)
+          or if it was already set to SIG_IGN (and should be left
+          untouched. */
        if (set_one_signal_handler(SIGHUP, exit_handler, 0) == -1 ||
            set_one_signal_handler(SIGINT, exit_handler, 0) == -1 ||
            set_one_signal_handler(SIGTERM, exit_handler, 0) == -1 ||
-           set_one_signal_handler(SIGPIPE, SIG_IGN, 0) == -1)
+           set_one_signal_handler(SIGPIPE, do_nothing, 0) == -1)
                return -1;
 
        fuse_instance = se;
@@ -78,5 +88,5 @@ void fuse_remove_signal_handlers(struct fuse_session *se)
        set_one_signal_handler(SIGHUP, exit_handler, 1);
        set_one_signal_handler(SIGINT, exit_handler, 1);
        set_one_signal_handler(SIGTERM, exit_handler, 1);
-       set_one_signal_handler(SIGPIPE, SIG_IGN, 1);
+       set_one_signal_handler(SIGPIPE, do_nothing, 1);
 }