diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-01-06 14:07:49 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-01-06 14:07:49 +0000 |
commit | a49ec1f9984778391e992b167d108a5e6b632758 (patch) | |
tree | 44a4148f741b6f93a0ddbcd73aa6359cb164b703 /usr.sbin/httpd/config.c | |
parent | 96deda13656045b8525045fe114105ab73f04f87 (diff) |
Only open a socket once for each unique "listen on" statement. This
prevents running out of file descriptors when loading a configuration
with many aliases.
OK florian@
Diffstat (limited to 'usr.sbin/httpd/config.c')
-rw-r--r-- | usr.sbin/httpd/config.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/usr.sbin/httpd/config.c b/usr.sbin/httpd/config.c index 14fe63e001c..4077d34898a 100644 --- a/usr.sbin/httpd/config.c +++ b/usr.sbin/httpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.27 2015/01/03 15:49:18 reyk Exp $ */ +/* $OpenBSD: config.c,v 1.28 2015/01/06 14:07:48 reyk Exp $ */ /* * Copyright (c) 2011 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -200,7 +200,9 @@ config_setserver(struct httpd *env, struct server *srv) n = -1; proc_range(ps, id, &n, &m); for (n = 0; n < m; n++) { - if ((fd = dup(srv->srv_s)) == -1) + if (srv->srv_s == -1) + fd = -1; + else if ((fd = dup(srv->srv_s)) == -1) return (-1); proc_composev_imsg(ps, id, n, IMSG_CFG_SERVER, fd, iov, c); @@ -211,9 +213,6 @@ config_setserver(struct httpd *env, struct server *srv) } } - close(srv->srv_s); - srv->srv_s = -1; - return (0); } @@ -356,8 +355,12 @@ config_getserver(struct httpd *env, struct imsg *imsg) if ((srv = server_byaddr((struct sockaddr *) &srv_conf.ss, srv_conf.port)) != NULL) { /* Add "host" to existing listening server */ - if (imsg->fd != -1) - close(imsg->fd); + if (imsg->fd != -1) { + if (srv->srv_s == -1) + srv->srv_s = imsg->fd; + else + close(imsg->fd); + } return (config_getserver_config(env, srv, imsg)); } |