From: reyk Date: Wed, 23 Jul 2014 13:26:39 +0000 (+0000) Subject: Correctly shutdown the servers when the process is terminating; X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b4ec2d25e51827bd0712d3e095e56592b221f399;p=openbsd Correctly shutdown the servers when the process is terminating; prevents a crash on exit. With debugging help from blambert@. --- diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c index 230ec35f85b..8dd395d3341 100644 --- a/usr.sbin/httpd/config.c +++ b/usr.sbin/httpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.2 2014/07/13 14:17:37 reyk Exp $ */ +/* $OpenBSD: config.c,v 1.3 2014/07/23 13:26:39 reyk Exp $ */ /* * Copyright (c) 2011 - 2014 Reyk Floeter @@ -90,10 +90,8 @@ config_purge(struct httpd *env, u_int reset) what = ps->ps_what[privsep_process] & reset; if (what & CONFIG_SERVERS && env->sc_servers != NULL) { - while ((srv = TAILQ_FIRST(env->sc_servers)) != NULL) { - TAILQ_REMOVE(env->sc_servers, srv, srv_entry); - free(srv); - } + while ((srv = TAILQ_FIRST(env->sc_servers)) != NULL) + server_purge(srv); } if (what & CONFIG_MEDIA && env->sc_mediatypes != NULL) diff --git a/usr.sbin/httpd/httpd.h b/usr.sbin/httpd/httpd.h index 75d6e44de3e..d23e6a8d97a 100644 --- a/usr.sbin/httpd/httpd.h +++ b/usr.sbin/httpd/httpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.h,v 1.5 2014/07/23 12:01:27 reyk Exp $ */ +/* $OpenBSD: httpd.h,v 1.6 2014/07/23 13:26:39 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -362,6 +362,7 @@ int cmdline_symset(char *); /* server.c */ pid_t server(struct privsep *, struct privsep_proc *); int server_privinit(struct server *); +void server_purge(struct server *); int server_socket_af(struct sockaddr_storage *, in_port_t); in_port_t server_socket_getport(struct sockaddr_storage *); diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c index 10f26e3f2df..38151ead061 100644 --- a/usr.sbin/httpd/server.c +++ b/usr.sbin/httpd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.6 2014/07/16 10:25:28 reyk Exp $ */ +/* $OpenBSD: server.c,v 1.7 2014/07/23 13:26:39 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -148,6 +148,28 @@ server_launch(void) } } +void +server_purge(struct server *srv) +{ + struct client *clt; + + /* shutdown and remove server */ + if (event_initialized(&srv->srv_ev)) + event_del(&srv->srv_ev); + if (evtimer_initialized(&srv->srv_evt)) + evtimer_del(&srv->srv_evt); + + close(srv->srv_s); + TAILQ_REMOVE(env->sc_servers, srv, srv_entry); + + /* cleanup sessions */ + while ((clt = + SPLAY_ROOT(&srv->srv_clients)) != NULL) + server_close(clt, NULL); + + free(srv); +} + int server_socket_af(struct sockaddr_storage *ss, in_port_t port) {