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 ();
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 );
136 pause_on_sigusr( int which
)
138 #if defined(HAVE_SIGPROCMASK) && defined(HAVE_SIGSET_T)
139 sigset_t mask
, oldmask
;
141 assert( which
== 1 );
142 sigemptyset( &mask
);
143 sigaddset( &mask
, SIGUSR1
);
145 sigprocmask( SIG_BLOCK
, &mask
, &oldmask
);
146 while( !caught_sigusr1
)
147 sigsuspend( &oldmask
);
149 sigprocmask( SIG_UNBLOCK
, &mask
, NULL
);
153 while (!caught_sigusr1
)
157 #endif /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
160 /* Disabled - see comment in tdbio.c:tdbio_begin_transaction() */
163 do_block( int block
)
165 static int is_blocked
;
166 #if defined(HAVE_SIGPROCMASK) && defined(HAVE_SIGSET_T)
167 static sigset_t oldmask
;
173 log_bug("signals are already blocked\n");
174 sigfillset( &newmask
);
175 sigprocmask( SIG_BLOCK
, &newmask
, &oldmask
);
180 log_bug("signals are not blocked\n");
181 sigprocmask( SIG_SETMASK
, &oldmask
, NULL
);
184 #else /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
187 #define SIGSMAX (NSIG)
188 #elif defined(MAXSIG)
189 #define SIGSMAX (MAXSIG+1)
191 #error "define SIGSMAX to the number of signals on your platform plus one"
194 static void (*disposition
[SIGSMAX
])(int);
199 log_bug("signals are already blocked\n");
200 for (sig
=1; sig
< SIGSMAX
; sig
++) {
201 disposition
[sig
] = sigset (sig
, SIG_HOLD
);
207 log_bug("signals are not blocked\n");
208 for (sig
=1; sig
< SIGSMAX
; sig
++) {
209 sigset (sig
, disposition
[sig
]);
213 #endif /*! HAVE_SIGPROCMASK && HAVE_SIGSET_T */
223 unblock_all_signals()
229 #endif /* !HAVE_DOSISH_SYSTEM */