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) {}
40 static volatile int caught_fatal_sig = 0;
41 static volatile int caught_sigusr1 = 0;
44 init_one_signal (int sig, RETSIGTYPE (*handler)(int), int check_ign )
46 #if defined(HAVE_SIGACTION) && defined(HAVE_STRUCT_SIGACTION)
47 struct sigaction oact, nact;
50 /* we don't want to change an IGN handler */
51 sigaction (sig, NULL, &oact );
52 if (oact.sa_handler == SIG_IGN )
56 nact.sa_handler = handler;
57 sigemptyset (&nact.sa_mask);
59 sigaction ( sig, &nact, NULL);
61 RETSIGTYPE (*ohandler)(int);
63 ohandler = signal (sig, handler);
64 if (check_ign && ohandler == SIG_IGN) {
65 /* Change it back if it was already set to IGN */
66 signal (sig, SIG_IGN);
72 got_fatal_signal( int sig )
76 if( caught_fatal_sig )
80 gcry_control (GCRYCTL_TERM_SECMEM );
82 tty_cleanup_rl_after_signal ();
83 tty_cleanup_after_signal ();
85 /* Better don't translate these messages. */
87 s = log_get_name(); if( s ) write(2, s, strlen(s) );
90 #if HAVE_DECL_SYS_SIGLIST && defined(NSIG)
91 s = (sig >= 0 && sig < NSIG) ? sys_siglist[sig] : "?";
92 write (2, s, strlen(s) );
94 write (2, "signal ", 7 );
95 if (sig < 0 || sig >=100)
99 write (2, "0123456789"+(sig/10), 1 );
100 write (2, "0123456789"+(sig%10), 1 );
103 write(2, " caught ... exiting\n", 20 );
105 /* Reset action to default action and raise signal again. */
106 init_one_signal (sig, SIG_DFL, 0);
107 dotlock_remove_lockfiles ();
110 #endif /* __riscos__ */
116 got_usr_signal( int sig )
125 init_one_signal (SIGINT, got_fatal_signal, 1 );
126 init_one_signal (SIGHUP, got_fatal_signal, 1 );
127 init_one_signal (SIGTERM, got_fatal_signal, 1 );
128 init_one_signal (SIGQUIT, got_fatal_signal, 1 );
129 init_one_signal (SIGSEGV, got_fatal_signal, 1 );
130 init_one_signal (SIGUSR1, got_usr_signal, 0 );
131 init_one_signal (SIGPIPE, SIG_IGN, 0 );
135 /* Disabled - see comment in tdbio.c:tdbio_begin_transaction() */
138 do_block( int block )
140 static int is_blocked;
141 #if defined(HAVE_SIGPROCMASK) && defined(HAVE_SIGSET_T)
142 static sigset_t oldmask;
148 log_bug("signals are already blocked\n");
149 sigfillset( &newmask );
150 sigprocmask( SIG_BLOCK, &newmask, &oldmask );
155 log_bug("signals are not blocked\n");
156 sigprocmask( SIG_SETMASK, &oldmask, NULL );
159 #else /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
162 #define SIGSMAX (NSIG)
163 #elif defined(MAXSIG)
164 #define SIGSMAX (MAXSIG+1)
166 #error "define SIGSMAX to the number of signals on your platform plus one"
169 static void (*disposition[SIGSMAX])(int);
174 log_bug("signals are already blocked\n");
175 for (sig=1; sig < SIGSMAX; sig++) {
176 disposition[sig] = sigset (sig, SIG_HOLD);
182 log_bug("signals are not blocked\n");
183 for (sig=1; sig < SIGSMAX; sig++) {
184 sigset (sig, disposition[sig]);
188 #endif /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
198 unblock_all_signals()
204 #endif /* !HAVE_DOSISH_SYSTEM */