forked from mirrors/tftp-hpa-google
signals: require and always use sigaction()
tftpd already requires sigaction() to compile, so there is no reason to use anything else. It also allows for nicer combination of flags. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
e52af4207a
commit
33051a296c
6 changed files with 22 additions and 55 deletions
|
@ -1,42 +1,19 @@
|
|||
/*
|
||||
* signal.c
|
||||
*
|
||||
* Use sigaction() to simulate BSD signal()
|
||||
* User-friendly wrapper around sigaction().
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
|
||||
sighandler_t tftp_signal(int signum, sighandler_t handler)
|
||||
int tftp_signal(int signum, sighandler_t handler, int flags)
|
||||
{
|
||||
struct sigaction action, oldaction;
|
||||
struct sigaction sa;
|
||||
|
||||
memset(&action, 0, sizeof action);
|
||||
action.sa_handler = handler;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaddset(&action.sa_mask, signum);
|
||||
action.sa_flags = SA_RESTART;
|
||||
memset(&sa, 0, sizeof sa);
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = flags;
|
||||
|
||||
if (sigaction(signum, &action, &oldaction))
|
||||
return SIG_ERR;
|
||||
|
||||
return oldaction.sa_handler;
|
||||
return sigaction(signum, &sa, NULL);
|
||||
}
|
||||
|
||||
#elif defined(HAVE_BSD_SIGNAL)
|
||||
|
||||
sighandler_t tftp_signal(int signum, sighandler_t handler)
|
||||
{
|
||||
return bsd_signal(signum, handler);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* This is dangerous at best. Let's hope it works. */
|
||||
sighandler_t tftp_signal(int signum, sighandler_t handler)
|
||||
{
|
||||
return signal(signum, handler);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue