summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2010-05-14 11:13:37 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2010-05-14 11:13:37 +0000
commit69cfced606e9755ce640af6e463cb96973577377 (patch)
tree4e1521978a8b2bcf1abe530326fbaa8e89fe3646 /usr.sbin
parentaf1420407e436fd56870244a8cf440bd1f534196 (diff)
allocate all struct event's on the heap, it looks cleaner, feels better
and follows a suggestion in event.h. also don't mix signal() and signal_set()/signal_add(). ok jsg@ gilles@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/relayd/hce.c26
-rw-r--r--usr.sbin/relayd/pfe.c26
-rw-r--r--usr.sbin/relayd/relay.c29
-rw-r--r--usr.sbin/relayd/relayd.c29
-rw-r--r--usr.sbin/relayd/relayd.h9
5 files changed, 77 insertions, 42 deletions
diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c
index 96a8aac9141..2eb5601d160 100644
--- a/usr.sbin/relayd/hce.c
+++ b/usr.sbin/relayd/hce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hce.c,v 1.54 2010/01/11 06:40:14 jsg Exp $ */
+/* $OpenBSD: hce.c,v 1.55 2010/05/14 11:13:36 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -62,6 +62,11 @@ hce_sig_handler(int sig, short event, void *arg)
case SIGTERM:
hce_shutdown();
break;
+ case SIGCHLD:
+ case SIGHUP:
+ case SIGPIPE:
+ /* ignore */
+ break;
default:
fatalx("hce_sig_handler: unexpected signal");
}
@@ -75,8 +80,6 @@ hce(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
pid_t pid;
struct passwd *pw;
int i;
- struct event ev_sigint;
- struct event ev_sigterm;
switch (pid = fork()) {
case -1:
@@ -135,12 +138,17 @@ hce(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
iev_main->handler, iev_main);
event_add(&iev_main->ev, NULL);
- signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
- signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
+ signal_set(&env->sc_evsigint, SIGINT, hce_sig_handler, env);
+ signal_set(&env->sc_evsigterm, SIGTERM, hce_sig_handler, env);
+ signal_set(&env->sc_evsigchld, SIGCHLD, hce_sig_handler, env);
+ signal_set(&env->sc_evsighup, SIGHUP, hce_sig_handler, env);
+ signal_set(&env->sc_evsigpipe, SIGPIPE, hce_sig_handler, env);
+
+ signal_add(&env->sc_evsigint, NULL);
+ signal_add(&env->sc_evsigterm, NULL);
+ signal_add(&env->sc_evsigchld, NULL);
+ signal_add(&env->sc_evsighup, NULL);
+ signal_add(&env->sc_evsigpipe, NULL);
/* setup pipes */
close(pipe_pfe2hce[1]);
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 0abd31918be..0a095385bab 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.63 2009/08/17 11:36:01 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.64 2010/05/14 11:13:36 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -59,6 +59,11 @@ pfe_sig_handler(int sig, short event, void *arg)
case SIGTERM:
pfe_shutdown();
break;
+ case SIGCHLD:
+ case SIGHUP:
+ case SIGPIPE:
+ /* ignore */
+ break;
default:
fatalx("pfe_sig_handler: unexpected signal");
}
@@ -71,8 +76,6 @@ pfe(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
{
pid_t pid;
struct passwd *pw;
- struct event ev_sigint;
- struct event ev_sigterm;
int i;
size_t size;
@@ -118,12 +121,17 @@ pfe(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
event_init();
- signal_set(&ev_sigint, SIGINT, pfe_sig_handler, NULL);
- signal_set(&ev_sigterm, SIGTERM, pfe_sig_handler, NULL);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
- signal(SIGPIPE, SIG_IGN);
- signal(SIGHUP, SIG_IGN);
+ signal_set(&env->sc_evsigint, SIGINT, pfe_sig_handler, env);
+ signal_set(&env->sc_evsigterm, SIGTERM, pfe_sig_handler, env);
+ signal_set(&env->sc_evsigchld, SIGCHLD, pfe_sig_handler, env);
+ signal_set(&env->sc_evsighup, SIGHUP, pfe_sig_handler, env);
+ signal_set(&env->sc_evsigpipe, SIGPIPE, pfe_sig_handler, env);
+
+ signal_add(&env->sc_evsigint, NULL);
+ signal_add(&env->sc_evsigterm, NULL);
+ signal_add(&env->sc_evsigchld, NULL);
+ signal_add(&env->sc_evsighup, NULL);
+ signal_add(&env->sc_evsigpipe, NULL);
/* setup pipes */
close(pipe_pfe2hce[0]);
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c
index 00e1f279036..751c35d81e5 100644
--- a/usr.sbin/relayd/relay.c
+++ b/usr.sbin/relayd/relay.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relay.c,v 1.119 2010/02/18 16:33:25 jsg Exp $ */
+/* $OpenBSD: relay.c,v 1.120 2010/05/14 11:13:36 reyk Exp $ */
/*
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -145,6 +145,14 @@ relay_sig_handler(int sig, short event, void *arg)
case SIGTERM:
case SIGINT:
(void)event_loopexit(NULL);
+ break;
+ case SIGCHLD:
+ case SIGHUP:
+ case SIGPIPE:
+ /* ignore */
+ break;
+ default:
+ fatalx("relay_sig_handler: unexpected signal");
}
}
@@ -155,8 +163,6 @@ relay(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
{
pid_t pid;
struct passwd *pw;
- struct event ev_sigint;
- struct event ev_sigterm;
int i;
switch (pid = fork()) {
@@ -210,12 +216,17 @@ relay(struct relayd *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
/* Per-child initialization */
relay_init();
- signal_set(&ev_sigint, SIGINT, relay_sig_handler, NULL);
- signal_set(&ev_sigterm, SIGTERM, relay_sig_handler, NULL);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
- signal(SIGHUP, SIG_IGN);
- signal(SIGPIPE, SIG_IGN);
+ signal_set(&env->sc_evsigint, SIGINT, relay_sig_handler, env);
+ signal_set(&env->sc_evsigterm, SIGTERM, relay_sig_handler, env);
+ signal_set(&env->sc_evsigchld, SIGCHLD, relay_sig_handler, env);
+ signal_set(&env->sc_evsighup, SIGHUP, relay_sig_handler, env);
+ signal_set(&env->sc_evsigpipe, SIGPIPE, relay_sig_handler, env);
+
+ signal_add(&env->sc_evsigint, NULL);
+ signal_add(&env->sc_evsigterm, NULL);
+ signal_add(&env->sc_evsigchld, NULL);
+ signal_add(&env->sc_evsighup, NULL);
+ signal_add(&env->sc_evsigpipe, NULL);
/* setup pipes */
close(pipe_pfe2hce[0]);
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index 7e6afa31a01..d3e3431b976 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.96 2010/02/17 14:39:30 jsg Exp $ */
+/* $OpenBSD: relayd.c,v 1.97 2010/05/14 11:13:36 reyk Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org>
@@ -104,6 +104,9 @@ main_sig_handler(int sig, short event, void *arg)
case SIGHUP:
reconfigure();
break;
+ case SIGPIPE:
+ /* ignore */
+ break;
default:
fatalx("unexpected signal");
}
@@ -128,10 +131,6 @@ main(int argc, char *argv[])
u_int32_t opts;
struct relayd *env;
const char *conffile;
- struct event ev_sigint;
- struct event ev_sigterm;
- struct event ev_sigchld;
- struct event ev_sighup;
struct imsgev *iev;
opts = 0;
@@ -237,15 +236,17 @@ main(int argc, char *argv[])
event_init();
- signal_set(&ev_sigint, SIGINT, main_sig_handler, env);
- signal_set(&ev_sigterm, SIGTERM, main_sig_handler, env);
- signal_set(&ev_sigchld, SIGCHLD, main_sig_handler, env);
- signal_set(&ev_sighup, SIGHUP, main_sig_handler, env);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
- signal_add(&ev_sigchld, NULL);
- signal_add(&ev_sighup, NULL);
- signal(SIGPIPE, SIG_IGN);
+ signal_set(&env->sc_evsigint, SIGINT, main_sig_handler, env);
+ signal_set(&env->sc_evsigterm, SIGTERM, main_sig_handler, env);
+ signal_set(&env->sc_evsigchld, SIGCHLD, main_sig_handler, env);
+ signal_set(&env->sc_evsighup, SIGHUP, main_sig_handler, env);
+ signal_set(&env->sc_evsigpipe, SIGPIPE, main_sig_handler, env);
+
+ signal_add(&env->sc_evsigint, NULL);
+ signal_add(&env->sc_evsigterm, NULL);
+ signal_add(&env->sc_evsigchld, NULL);
+ signal_add(&env->sc_evsighup, NULL);
+ signal_add(&env->sc_evsigpipe, NULL);
close(pipe_parent2pfe[1]);
close(pipe_parent2hce[1]);
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 8fffd228696..24c86bf865b 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.134 2010/05/14 07:57:07 reyk Exp $ */
+/* $OpenBSD: relayd.h,v 1.135 2010/05/14 11:13:36 reyk Exp $ */
/*
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -671,6 +671,13 @@ struct relayd {
struct ctl_icmp_event sc_icmp_recv;
struct ctl_icmp_event sc_icmp6_send;
struct ctl_icmp_event sc_icmp6_recv;
+
+ /* Event and signal handlers */
+ struct event sc_evsigint;
+ struct event sc_evsigterm;
+ struct event sc_evsigchld;
+ struct event sc_evsighup;
+ struct event sc_evsigpipe;
};
#define RELAYD_OPT_VERBOSE 0x01