2 FUSE: Filesystem in Userspace
3 Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
5 This program can be distributed under the terms of the GNU LGPLv2.
6 See the file COPYING.LIB
10 #include "fuse_lowlevel.h"
16 static struct fuse_session
*fuse_instance
;
18 static void exit_handler(int sig
)
22 fuse_session_exit(fuse_instance
);
25 static int set_one_signal_handler(int sig
, void (*handler
)(int))
28 struct sigaction old_sa
;
30 memset(&sa
, 0, sizeof(struct sigaction
));
31 sa
.sa_handler
= handler
;
32 sigemptyset(&(sa
.sa_mask
));
35 if (sigaction(sig
, NULL
, &old_sa
) == -1) {
36 perror("fuse: cannot get old signal handler");
40 if (old_sa
.sa_handler
== SIG_DFL
&&
41 sigaction(sig
, &sa
, NULL
) == -1) {
42 perror("fuse: cannot set signal handler");
48 int fuse_set_signal_handlers(struct fuse_session
*se
)
50 if (set_one_signal_handler(SIGHUP
, exit_handler
) == -1 ||
51 set_one_signal_handler(SIGINT
, exit_handler
) == -1 ||
52 set_one_signal_handler(SIGTERM
, exit_handler
) == -1 ||
53 set_one_signal_handler(SIGPIPE
, SIG_IGN
) == -1)
60 void fuse_remove_signal_handlers(struct fuse_session
*se
)
62 if (fuse_instance
!= se
)
64 "fuse: fuse_remove_signal_handlers: unknown session\n");
68 set_one_signal_handler(SIGHUP
, SIG_DFL
);
69 set_one_signal_handler(SIGINT
, SIG_DFL
);
70 set_one_signal_handler(SIGTERM
, SIG_DFL
);
71 set_one_signal_handler(SIGPIPE
, SIG_DFL
);