1 /* Copyright 1996,1997,2001,2002,2007,2009 Alain Knaff.
2 * This file is part of mtools.
4 * Mtools is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Mtools is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
18 #include "sysincludes.h"
25 static void signal_handler(int dummy UNUSEDP)
29 signal(SIGHUP, SIG_IGN);
30 signal(SIGINT, SIG_IGN);
31 signal(SIGTERM, SIG_IGN);
32 signal(SIGQUIT, SIG_IGN);
37 int do_gotsignal(char *f, int n)
40 fprintf(stderr, "file=%s line=%d\n", f, n);
45 void setup_signal(void)
49 signal(SIGHUP, signal_handler);
52 signal(SIGINT, signal_handler);
55 signal(SIGTERM, signal_handler);
58 signal(SIGQUIT, signal_handler);
63 static void _allow_interrupt(saved_sig_state *ss, int sig, int slot)
67 memset(&new, 0, sizeof(new));
68 new.sa_handler = signal_handler;
69 new.sa_flags &= ~SA_RESTART;
71 if(sigaction(sig, &new, &ss->sa[slot]) < 0) {
78 /* Allow syscalls to be interrupted by signal */
79 void allow_interrupts(saved_sig_state *ss)
84 _allow_interrupt(ss, SIGINT, 0);
88 _allow_interrupt(ss, SIGINT, 1);
92 _allow_interrupt(ss, SIGINT, 2);
96 _allow_interrupt(ss, SIGINT, 3);
102 #ifdef HAVE_SIGACTION
103 static void _restore_interrupt(saved_sig_state *ss, int sig, int slot)
105 if(sigaction(sig, &ss->sa[slot], NULL) < 0) {
106 perror("restore sigaction");
112 /* Restore syscalls to be interrupted by signal */
113 void restore_interrupts(saved_sig_state *ss)
115 #ifdef HAVE_SIGACTION
118 _restore_interrupt(ss, SIGINT, 0);
122 _restore_interrupt(ss, SIGINT, 1);
126 _restore_interrupt(ss, SIGINT, 2);
130 _restore_interrupt(ss, SIGINT, 3);