prevents a crash on exit. With debugging help from blambert@.
-/* $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 <reyk@openbsd.org>
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)
-/* $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 <reyk@openbsd.org>
/* 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 *);
-/* $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 <reyk@openbsd.org>
}
}
+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)
{