forked from mirrors/tftp-hpa-google
Modernize: use sigaction() whenever possible. Remove uses of common.
bsd_signal() may not be defined, and there is really no reason to even try to use it if sigaction() is avaiable; using sigaction() guarantees the semantics we really want. Replace uses of common variables with explicit instantiation and extern declarations in a header file. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
9c0908a778
commit
1f4b33a1f7
9 changed files with 64 additions and 42 deletions
42
common/signal.c
Normal file
42
common/signal.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* signal.c
|
||||
*
|
||||
* Use sigaction() to simulate BSD signal()
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef HAVE_SIGACTION
|
||||
|
||||
sighandler_t tftp_signal(int signum, sighandler_t handler)
|
||||
{
|
||||
struct sigaction action, oldaction;
|
||||
|
||||
memset(&action, 0, sizeof action);
|
||||
action.sa_handler = handler;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaddset(&action.sa_mask, signum);
|
||||
action.sa_flags = SA_RESTART;
|
||||
|
||||
if (sigaction(signum, &action, &oldaction))
|
||||
return SIG_ERR;
|
||||
|
||||
return oldaction.sa_handler;
|
||||
}
|
||||
|
||||
#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