diff options
author | helg <helg@cvs.openbsd.org> | 2018-07-05 10:57:32 +0000 |
---|---|---|
committer | helg <helg@cvs.openbsd.org> | 2018-07-05 10:57:32 +0000 |
commit | 9cde2cb91ef0f6ad8d8e2cf36e744028a4cb7b28 (patch) | |
tree | 10b8aab47d0e5b6030c10e3d22af26f412f33006 | |
parent | fe832e2de612ee96306d7230d9cc442779cf3dd3 (diff) |
fuse_set_signal_handlers(3) and fuse_remove_signal_handlers(3) should
not replace any existing signal handlers. This makes it possible for
FUSE file systems to install their own signal handlers. Bug reported
by Bill Zissimopoulos.
ok mpi@
-rw-r--r-- | lib/libfuse/fuse.c | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/lib/libfuse/fuse.c b/lib/libfuse/fuse.c index cc5f8c50c8c..ffd1ce84119 100644 --- a/lib/libfuse/fuse.c +++ b/lib/libfuse/fuse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse.c,v 1.48 2018/07/03 23:23:26 helg Exp $ */ +/* $OpenBSD: fuse.c,v 1.49 2018/07/05 10:57:31 helg Exp $ */ /* * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com> * @@ -476,20 +476,51 @@ DEF(fuse_destroy); void fuse_remove_signal_handlers(unused struct fuse_session *se) { - signal(SIGHUP, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - signal(SIGPIPE, SIG_DFL); + struct sigaction old_sa; + + if (sigaction(SIGHUP, NULL, &old_sa) == 0) + if (old_sa.sa_handler == ifuse_sighdlr) + signal(SIGHUP, SIG_DFL); + + if (sigaction(SIGINT, NULL, &old_sa) == 0) + if (old_sa.sa_handler == ifuse_sighdlr) + signal(SIGINT, SIG_DFL); + + if (sigaction(SIGTERM, NULL, &old_sa) == 0) + if (old_sa.sa_handler == ifuse_sighdlr) + signal(SIGTERM, SIG_DFL); + + if (sigaction(SIGPIPE, NULL, &old_sa) == 0) + if (old_sa.sa_handler == SIG_IGN) + signal(SIGPIPE, SIG_DFL); } DEF(fuse_remove_signal_handlers); int fuse_set_signal_handlers(unused struct fuse_session *se) { - signal(SIGHUP, ifuse_sighdlr); - signal(SIGINT, ifuse_sighdlr); - signal(SIGTERM, ifuse_sighdlr); - signal(SIGPIPE, SIG_IGN); + struct sigaction old_sa; + + if (sigaction(SIGHUP, NULL, &old_sa) == -1) + return (-1); + if (old_sa.sa_handler == SIG_DFL) + signal(SIGHUP, ifuse_sighdlr); + + if (sigaction(SIGINT, NULL, &old_sa) == -1) + return (-1); + if (old_sa.sa_handler == SIG_DFL) + signal(SIGINT, ifuse_sighdlr); + + if (sigaction(SIGTERM, NULL, &old_sa) == -1) + return (-1); + if (old_sa.sa_handler == SIG_DFL) + signal(SIGTERM, ifuse_sighdlr); + + if (sigaction(SIGPIPE, NULL, &old_sa) == -1) + return (-1); + if (old_sa.sa_handler == SIG_DFL) + signal(SIGPIPE, SIG_IGN); + return (0); } |