diff options
author | Miklos Szeredi <mszeredi@suse.cz> | 2015-02-26 16:57:41 +0100 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2015-02-26 16:58:37 +0100 |
commit | cd757d22b4340991f6b085ffb626020ee4c4fefa (patch) | |
tree | 9722d9fc48ca1adfe30a849368acbdee2d26f810 | |
parent | 4163109fd5bfe67973262610dd95ae60888c92e9 (diff) | |
download | fuse-cd757d22b4340991f6b085ffb626020ee4c4fefa.tar.gz |
libfuse: fix fuse_remove_signal_handlers()
to properly restore the default signal handler.
Reported by: Chris Johnson <johnsocg@gmail.com>
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/fuse_signals.c | 22 |
2 files changed, 16 insertions, 11 deletions
@@ -1,3 +1,8 @@ +2015-02-26 Miklos Szeredi <miklos@szeredi.hu> + + * libfuse: fix fuse_remove_signal_handlers() to properly restore + the default signal handler. Reported by: Chris Johnson + 2014-07-21 Miklos Szeredi <miklos@szeredi.hu> * libfuse: highlevel API: fix directory file handle passed to diff --git a/lib/fuse_signals.c b/lib/fuse_signals.c index 88ac39e..353cb24 100644 --- a/lib/fuse_signals.c +++ b/lib/fuse_signals.c @@ -21,13 +21,13 @@ static void exit_handler(int sig) fuse_session_exit(fuse_instance); } -static int set_one_signal_handler(int sig, void (*handler)(int)) +static int set_one_signal_handler(int sig, void (*handler)(int), int remove) { struct sigaction sa; struct sigaction old_sa; memset(&sa, 0, sizeof(struct sigaction)); - sa.sa_handler = handler; + sa.sa_handler = remove ? SIG_DFL : handler; sigemptyset(&(sa.sa_mask)); sa.sa_flags = 0; @@ -36,7 +36,7 @@ static int set_one_signal_handler(int sig, void (*handler)(int)) return -1; } - if (old_sa.sa_handler == SIG_DFL && + if (old_sa.sa_handler == (remove ? handler : SIG_DFL) && sigaction(sig, &sa, NULL) == -1) { perror("fuse: cannot set signal handler"); return -1; @@ -46,10 +46,10 @@ static int set_one_signal_handler(int sig, void (*handler)(int)) int fuse_set_signal_handlers(struct fuse_session *se) { - if (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) + 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) return -1; fuse_instance = se; @@ -64,9 +64,9 @@ void fuse_remove_signal_handlers(struct fuse_session *se) else fuse_instance = NULL; - set_one_signal_handler(SIGHUP, SIG_DFL); - set_one_signal_handler(SIGINT, SIG_DFL); - set_one_signal_handler(SIGTERM, SIG_DFL); - set_one_signal_handler(SIGPIPE, SIG_DFL); + 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); } |