mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Update head to match stable 1.0
This commit is contained in:
parent
151ee2f47b
commit
3f51f7db3d
155 changed files with 83872 additions and 37585 deletions
124
g10/signal.c
124
g10/signal.c
|
@ -1,5 +1,5 @@
|
|||
/* signal.c - signal handling
|
||||
* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
|
||||
* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -27,9 +27,9 @@
|
|||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <gcrypt.h>
|
||||
#include "options.h"
|
||||
#include "errors.h"
|
||||
#include "memory.h"
|
||||
#include "util.h"
|
||||
#include "main.h"
|
||||
#include "ttyio.h"
|
||||
|
@ -38,6 +38,36 @@
|
|||
static volatile int caught_fatal_sig = 0;
|
||||
static volatile int caught_sigusr1 = 0;
|
||||
|
||||
static void
|
||||
init_one_signal (int sig, RETSIGTYPE (*handler)(int), int check_ign )
|
||||
{
|
||||
#ifndef HAVE_DOSISH_SYSTEM
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction oact, nact;
|
||||
|
||||
if (check_ign) {
|
||||
/* we don't want to change an IGN handler */
|
||||
sigaction (sig, NULL, &oact );
|
||||
if (oact.sa_handler == SIG_IGN )
|
||||
return;
|
||||
}
|
||||
|
||||
nact.sa_handler = handler;
|
||||
sigemptyset (&nact.sa_mask);
|
||||
nact.sa_flags = 0;
|
||||
sigaction ( sig, &nact, NULL);
|
||||
#else
|
||||
RETSIGTYPE (*ohandler)(int);
|
||||
|
||||
ohandler = signal (sig, handler);
|
||||
if (check_ign && ohandler == SIG_IGN) {
|
||||
/* Change it back if it was already set to IGN */
|
||||
signal (sig, SIG_IGN);
|
||||
}
|
||||
#endif
|
||||
#endif /*!HAVE_DOSISH_SYSTEM*/
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_signal_name( int signum )
|
||||
{
|
||||
|
@ -58,23 +88,20 @@ got_fatal_signal( int sig )
|
|||
raise( sig );
|
||||
caught_fatal_sig = 1;
|
||||
|
||||
gcry_control( GCRYCTL_TERM_SECMEM );
|
||||
secmem_term();
|
||||
/* better don't transtale these messages */
|
||||
write(2, "\n", 1 );
|
||||
s = log_get_name(); if( s ) write(2, s, strlen(s) );
|
||||
write(2, ": ", 2 );
|
||||
s = get_signal_name(sig); write(2, s, strlen(s) );
|
||||
write(2, " caught ... exiting\n", 21 );
|
||||
write(2, " caught ... exiting\n", 20 );
|
||||
|
||||
#ifndef HAVE_DOSISH_SYSTEM
|
||||
{ /* reset action to default action and raise signal again */
|
||||
struct sigaction nact;
|
||||
nact.sa_handler = SIG_DFL;
|
||||
sigemptyset( &nact.sa_mask );
|
||||
nact.sa_flags = 0;
|
||||
sigaction( sig, &nact, NULL);
|
||||
}
|
||||
#endif
|
||||
/* reset action to default action and raise signal again */
|
||||
init_one_signal (sig, SIG_DFL, 0);
|
||||
remove_lockfiles ();
|
||||
#ifdef __riscos__
|
||||
close_fds ();
|
||||
#endif /* __riscos__ */
|
||||
raise( sig );
|
||||
}
|
||||
|
||||
|
@ -85,37 +112,18 @@ got_usr_signal( int sig )
|
|||
caught_sigusr1 = 1;
|
||||
}
|
||||
|
||||
#ifndef HAVE_DOSISH_SYSTEM
|
||||
static void
|
||||
do_sigaction( int sig, struct sigaction *nact )
|
||||
{
|
||||
struct sigaction oact;
|
||||
|
||||
sigaction( sig, NULL, &oact );
|
||||
if( oact.sa_handler != SIG_IGN )
|
||||
sigaction( sig, nact, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
init_signals()
|
||||
{
|
||||
#ifndef HAVE_DOSISH_SYSTEM
|
||||
struct sigaction nact;
|
||||
|
||||
nact.sa_handler = got_fatal_signal;
|
||||
sigemptyset( &nact.sa_mask );
|
||||
nact.sa_flags = 0;
|
||||
|
||||
do_sigaction( SIGINT, &nact );
|
||||
do_sigaction( SIGHUP, &nact );
|
||||
do_sigaction( SIGTERM, &nact );
|
||||
do_sigaction( SIGQUIT, &nact );
|
||||
do_sigaction( SIGSEGV, &nact );
|
||||
nact.sa_handler = got_usr_signal;
|
||||
sigaction( SIGUSR1, &nact, NULL );
|
||||
nact.sa_handler = SIG_IGN;
|
||||
sigaction( SIGPIPE, &nact, NULL );
|
||||
init_one_signal (SIGINT, got_fatal_signal, 1 );
|
||||
init_one_signal (SIGHUP, got_fatal_signal, 1 );
|
||||
init_one_signal (SIGTERM, got_fatal_signal, 1 );
|
||||
init_one_signal (SIGQUIT, got_fatal_signal, 1 );
|
||||
init_one_signal (SIGSEGV, got_fatal_signal, 1 );
|
||||
init_one_signal (SIGUSR1, got_usr_signal, 0 );
|
||||
init_one_signal (SIGPIPE, SIG_IGN, 0 );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -124,6 +132,7 @@ void
|
|||
pause_on_sigusr( int which )
|
||||
{
|
||||
#ifndef HAVE_DOSISH_SYSTEM
|
||||
#ifdef HAVE_SIGPROCMASK
|
||||
sigset_t mask, oldmask;
|
||||
|
||||
assert( which == 1 );
|
||||
|
@ -135,6 +144,14 @@ pause_on_sigusr( int which )
|
|||
sigsuspend( &oldmask );
|
||||
caught_sigusr1 = 0;
|
||||
sigprocmask( SIG_UNBLOCK, &mask, NULL );
|
||||
#else
|
||||
assert (which == 1);
|
||||
sighold (SIGUSR1);
|
||||
while (!caught_sigusr1)
|
||||
sigpause(SIGUSR1);
|
||||
caught_sigusr1 = 0;
|
||||
sigrelse(SIGUSR1); ????
|
||||
#endif /*!HAVE_SIGPROCMASK*/
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -142,12 +159,13 @@ pause_on_sigusr( int which )
|
|||
static void
|
||||
do_block( int block )
|
||||
{
|
||||
#ifndef HAVE_DOSISH_SYSTEM
|
||||
#ifndef HAVE_DOSISH_SYSTEM
|
||||
static int is_blocked;
|
||||
#ifdef HAVE_SIGPROCMASK
|
||||
static sigset_t oldmask;
|
||||
|
||||
if( block ) {
|
||||
sigset_t newmask;
|
||||
sigset_t newmask;
|
||||
|
||||
if( is_blocked )
|
||||
log_bug("signals are already blocked\n");
|
||||
|
@ -161,7 +179,28 @@ do_block( int block )
|
|||
sigprocmask( SIG_SETMASK, &oldmask, NULL );
|
||||
is_blocked = 0;
|
||||
}
|
||||
#endif /*HAVE_DOSISH_SYSTEM*/
|
||||
#else /*!HAVE_SIGPROCMASK*/
|
||||
static void (*disposition[MAXSIG])();
|
||||
int sig;
|
||||
|
||||
if( block ) {
|
||||
if( is_blocked )
|
||||
log_bug("signals are already blocked\n");
|
||||
for (sig=1; sig < MAXSIG; sig++) {
|
||||
disposition[sig] = sigset (sig, SIG_HOLD);
|
||||
}
|
||||
is_blocked = 1;
|
||||
}
|
||||
else {
|
||||
if( !is_blocked )
|
||||
log_bug("signals are not blocked\n");
|
||||
for (sig=1; sig < MAXSIG; sig++) {
|
||||
sigset (sig, disposition[sig]);
|
||||
}
|
||||
is_blocked = 0;
|
||||
}
|
||||
#endif /*!HAVE_SIGPROCMASK*/
|
||||
#endif /*HAVE_DOSISH_SYSTEM*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -176,4 +215,3 @@ unblock_all_signals()
|
|||
{
|
||||
do_block(0);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue