summaryrefslogtreecommitdiff
path: root/usr.sbin/ftp-proxy
diff options
context:
space:
mode:
authorCamiel Dobbelaar <camield@cvs.openbsd.org>2006-03-22 10:16:04 +0000
committerCamiel Dobbelaar <camield@cvs.openbsd.org>2006-03-22 10:16:04 +0000
commitf18d04c61f8638df81719a6648f8b862ceeb1b26 (patch)
tree9ce81272a224403fb3a9fc5dd1527144770f1cb8 /usr.sbin/ftp-proxy
parentbc8344446301cbb4f383b2e9e226b63ddf27cf1c (diff)
Rework signal handling the idiomatic libevent way. From ospfd.
ok claudio henning
Diffstat (limited to 'usr.sbin/ftp-proxy')
-rw-r--r--usr.sbin/ftp-proxy/ftp-proxy.c45
1 files changed, 25 insertions, 20 deletions
diff --git a/usr.sbin/ftp-proxy/ftp-proxy.c b/usr.sbin/ftp-proxy/ftp-proxy.c
index 4a195571274..6fbe8761856 100644
--- a/usr.sbin/ftp-proxy/ftp-proxy.c
+++ b/usr.sbin/ftp-proxy/ftp-proxy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ftp-proxy.c,v 1.7 2005/11/18 08:49:32 camield Exp $ */
+/* $OpenBSD: ftp-proxy.c,v 1.8 2006/03/22 10:16:03 camield Exp $ */
/*
* Copyright (c) 2004, 2005 Camiel Dobbelaar, <cd@sentia.nl>
@@ -84,7 +84,6 @@ struct session {
LIST_HEAD(, session) sessions = LIST_HEAD_INITIALIZER(sessions);
-void catch_signal(int);
void client_error(struct bufferevent *, short, void *);
int client_parse(struct session *s);
int client_parse_anon(struct session *s);
@@ -96,6 +95,7 @@ void end_session(struct session *);
int exit_daemon(void);
int getline(char *, size_t *);
void handle_connection(const int, short, void *);
+void handle_signal(int, short, void *);
struct session * init_session(void);
void logmsg(int, const char *, ...);
u_int16_t parse_port(int);
@@ -121,15 +121,6 @@ int anonymous_only, caught_sig, daemonize, id_count, ipv6_mode, loglevel,
extern char *__progname;
void
-catch_signal(int sig)
-{
- extern int event_gotsig;
-
- event_gotsig = 1;
- caught_sig = sig;
-}
-
-void
client_error(struct bufferevent *bufev, short what, void *arg)
{
struct session *s = arg;
@@ -319,8 +310,6 @@ exit_daemon(void)
{
struct session *s, *next;
- logmsg(LOG_ERR, "%s exiting on signal %d", __progname, caught_sig);
-
for (s = LIST_FIRST(&sessions); s != LIST_END(&sessions); s = next) {
next = LIST_NEXT(s, entry);
end_session(s);
@@ -519,6 +508,19 @@ handle_connection(const int listen_fd, short event, void *ev)
end_session(s);
}
+void
+handle_signal(int sig, short event, void *arg)
+{
+ /*
+ * Signal handler rules don't apply, libevent decouples for us.
+ */
+
+ logmsg(LOG_ERR, "%s exiting on signal %d", __progname, sig);
+
+ exit_daemon();
+}
+
+
struct session *
init_session(void)
{
@@ -575,10 +577,9 @@ logmsg(int pri, const char *message, ...)
int
main(int argc, char *argv[])
{
- extern int (*event_sigcb)(void);
struct rlimit rlp;
struct addrinfo hints, *res;
- struct event ev;
+ struct event ev, ev_sighup, ev_sigint, ev_sigterm;
int ch, error, listenfd, on;
/* Defaults. */
@@ -741,14 +742,18 @@ main(int argc, char *argv[])
}
event_init();
+
+ /* Setup signal handler. */
+ signal_set(&ev_sighup, SIGHUP, handle_signal, NULL);
+ signal_set(&ev_sigint, SIGINT, handle_signal, NULL);
+ signal_set(&ev_sigterm, SIGTERM, handle_signal, NULL);
+ signal_add(&ev_sighup, NULL);
+ signal_add(&ev_sigint, NULL);
+ signal_add(&ev_sigterm, NULL);
+
event_set(&ev, listenfd, EV_READ | EV_PERSIST, handle_connection, &ev);
event_add(&ev, NULL);
- signal(SIGHUP, catch_signal);
- signal(SIGINT, catch_signal);
- signal(SIGTERM, catch_signal);
- event_sigcb = exit_daemon;
-
logmsg(LOG_NOTICE, "listening on %s port %s", listen_ip, listen_port);
/* Vroom, vroom. */