Use sigaction() to have a consistent behavior across systems for signals.

This commit is contained in:
Nikos Mavrogiannopoulos
2013-05-02 11:46:02 +03:00
parent a84664733a
commit 67e83f89d7
10 changed files with 41 additions and 29 deletions

View File

@@ -18,7 +18,7 @@ ocserv_SOURCES = main.c main-auth.c worker-vpn.c worker-auth.c tlslib.c \
config.c pam.c pam.h worker-resume.c worker.h main-resume.c main.h \
main-user.c cookies-gdbm.c cookies-hash.c worker-misc.c setproctitle.h \
setproctitle.c worker-privs.c plain.c plain.h common.h common.c \
sec-mod.c sec-mod.h script-list.h die.c die.h icmp-ping.c icmp-ping.h \
sec-mod.c sec-mod.h script-list.h system.c system.h icmp-ping.c icmp-ping.h \
$(CCAN_SOURCES)
ocserv_SOURCES += ocserv-args.def ocserv-args.c ocserv-args.h

View File

@@ -1,6 +0,0 @@
#ifndef DIE_H
# define DIE_H
void kill_on_parent_kill(int sig);
#endif

View File

@@ -28,14 +28,13 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
#include <system.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>
#include <tlslib.h>
#include <sys/un.h>
#include "die.h"
#include <cloexec.h>
#include "ipc.h"
#include "setproctitle.h"

View File

@@ -28,7 +28,6 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <gnutls/gnutls.h>

View File

@@ -28,7 +28,6 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <gnutls/gnutls.h>

View File

@@ -28,7 +28,7 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
#include <system.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
@@ -38,7 +38,6 @@
#include <gnutls/x509.h>
#include <tlslib.h>
#include "ipc.h"
#include "die.h"
#include "setproctitle.h"
#ifdef HAVE_LIBWRAP
# include <tcpd.h>
@@ -638,12 +637,12 @@ int main(int argc, char** argv)
tun_st_init(&tun);
tls_cache_init(&s.tls_db);
signal(SIGINT, handle_term);
signal(SIGTERM, handle_term);
signal(SIGPIPE, SIG_IGN);
signal(SIGHUP, handle_reload);
signal(SIGCHLD, handle_children);
signal(SIGALRM, handle_alarm);
ocsignal(SIGINT, handle_term);
ocsignal(SIGTERM, handle_term);
ocsignal(SIGPIPE, SIG_IGN);
ocsignal(SIGHUP, handle_reload);
ocsignal(SIGCHLD, handle_children);
ocsignal(SIGALRM, handle_alarm);
/* Initialize GnuTLS */
tls_global_init(&s);

View File

@@ -29,7 +29,7 @@
#include <fcntl.h>
#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
#include <system.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/un.h>
@@ -163,9 +163,9 @@ uint16_t length;
struct iovec iov[2];
int sd;
signal(SIGHUP, SIG_IGN);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
ocsignal(SIGHUP, SIG_IGN);
ocsignal(SIGINT, SIG_DFL);
ocsignal(SIGTERM, SIG_DFL);
#ifdef HAVE_PKCS11
ret = gnutls_pkcs11_reinit();

View File

@@ -16,7 +16,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <system.h>
#include <unistd.h>
#ifdef __linux__
# include <sys/prctl.h>
@@ -28,3 +28,15 @@ void kill_on_parent_kill(int sig)
prctl(PR_SET_PDEATHSIG, sig);
#endif
}
sighandler_t ocsignal(int signum, sighandler_t handler)
{
struct sigaction new_action, old_action;
new_action.sa_handler = handler;
sigemptyset (&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction (signum, &new_action, &old_action);
return old_action.sa_handler;
}

10
src/system.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef DIE_H
# define DIE_H
# include <signal.h>
void kill_on_parent_kill(int sig);
sighandler_t ocsignal(int signum, sighandler_t handler);
#endif

View File

@@ -38,7 +38,7 @@
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <signal.h>
#include <system.h>
#include <time.h>
#include <common.h>
@@ -480,10 +480,10 @@ void vpn_server(struct worker_st* ws)
url_handler_fn fn;
int requests_left = MAX_HTTP_REQUESTS;
signal(SIGTERM, handle_term);
signal(SIGINT, handle_term);
signal(SIGHUP, SIG_IGN);
signal(SIGALRM, handle_alarm);
ocsignal(SIGTERM, handle_term);
ocsignal(SIGINT, handle_term);
ocsignal(SIGHUP, SIG_IGN);
ocsignal(SIGALRM, handle_alarm);
if (ws->config->auth_timeout)
alarm(ws->config->auth_timeout);