1 /* signal.c - signal handling
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 * 2005 Free Software Foundation, Inc.
5 * This file is part of GnuPG.
7 * GnuPG is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuPG is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
37 #ifdef HAVE_DOSISH_SYSTEM
38 void init_signals(void) {}
39 void pause_on_sigusr(int which) {}
41 static volatile int caught_fatal_sig = 0;
42 static volatile int caught_sigusr1 = 0;
45 init_one_signal (int sig, RETSIGTYPE (*handler)(int), int check_ign )
47 #if defined(HAVE_SIGACTION) && defined(HAVE_STRUCT_SIGACTION)
48 struct sigaction oact, nact;
51 /* we don't want to change an IGN handler */
52 sigaction (sig, NULL, &oact );
53 if (oact.sa_handler == SIG_IGN )
57 nact.sa_handler = handler;
58 sigemptyset (&nact.sa_mask);
60 sigaction ( sig, &nact, NULL);
62 RETSIGTYPE (*ohandler)(int);
64 ohandler = signal (sig, handler);
65 if (check_ign && ohandler == SIG_IGN) {
66 /* Change it back if it was already set to IGN */
67 signal (sig, SIG_IGN);
73 got_fatal_signal( int sig )
77 if( caught_fatal_sig )
81 gcry_control (GCRYCTL_TERM_SECMEM );
83 tty_cleanup_rl_after_signal ();
84 tty_cleanup_after_signal ();
86 /* Better don't translate these messages. */
88 s = log_get_name(); if( s ) write(2, s, strlen(s) );
91 #if HAVE_DECL_SYS_SIGLIST && defined(NSIG)
92 s = (sig >= 0 && sig < NSIG) ? sys_siglist[sig] : "?";
93 write (2, s, strlen(s) );
95 write (2, "signal ", 7 );
96 if (sig < 0 || sig >=100)
100 write (2, "0123456789"+(sig/10), 1 );
101 write (2, "0123456789"+(sig%10), 1 );
104 write(2, " caught ... exiting\n", 20 );
106 /* Reset action to default action and raise signal again. */
107 init_one_signal (sig, SIG_DFL, 0);
108 dotlock_remove_lockfiles ();
111 #endif /* __riscos__ */
117 got_usr_signal( int sig )
126 init_one_signal (SIGINT, got_fatal_signal, 1 );
127 init_one_signal (SIGHUP, got_fatal_signal, 1 );
128 init_one_signal (SIGTERM, got_fatal_signal, 1 );
129 init_one_signal (SIGQUIT, got_fatal_signal, 1 );
130 init_one_signal (SIGSEGV, got_fatal_signal, 1 );
131 init_one_signal (SIGUSR1, got_usr_signal, 0 );
132 init_one_signal (SIGPIPE, SIG_IGN, 0 );
137 pause_on_sigusr( int which )
139 #if defined(HAVE_SIGPROCMASK) && defined(HAVE_SIGSET_T)
140 sigset_t mask, oldmask;
142 assert( which == 1 );
143 sigemptyset( &mask );
144 sigaddset( &mask, SIGUSR1 );
146 sigprocmask( SIG_BLOCK, &mask, &oldmask );
147 while( !caught_sigusr1 )
148 sigsuspend( &oldmask );
150 sigprocmask( SIG_UNBLOCK, &mask, NULL );
154 while (!caught_sigusr1)
158 #endif /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
161 /* Disabled - see comment in tdbio.c:tdbio_begin_transaction() */
164 do_block( int block )
166 static int is_blocked;
167 #if defined(HAVE_SIGPROCMASK) && defined(HAVE_SIGSET_T)
168 static sigset_t oldmask;
174 log_bug("signals are already blocked\n");
175 sigfillset( &newmask );
176 sigprocmask( SIG_BLOCK, &newmask, &oldmask );
181 log_bug("signals are not blocked\n");
182 sigprocmask( SIG_SETMASK, &oldmask, NULL );
185 #else /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
188 #define SIGSMAX (NSIG)
189 #elif defined(MAXSIG)
190 #define SIGSMAX (MAXSIG+1)
192 #error "define SIGSMAX to the number of signals on your platform plus one"
195 static void (*disposition[SIGSMAX])(int);
200 log_bug("signals are already blocked\n");
201 for (sig=1; sig < SIGSMAX; sig++) {
202 disposition[sig] = sigset (sig, SIG_HOLD);
208 log_bug("signals are not blocked\n");
209 for (sig=1; sig < SIGSMAX; sig++) {
210 sigset (sig, disposition[sig]);
214 #endif /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
224 unblock_all_signals()
230 #endif /* !HAVE_DOSISH_SYSTEM */