]> err.no Git - varnish/commitdiff
Don't leak listen address structures if we fail to bind to them.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 9 Jun 2008 13:11:45 +0000 (13:11 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 9 Jun 2008 13:11:45 +0000 (13:11 +0000)
Associate ascii representation addr/port strings with each listen
socket, already in the manager process.

Postpone listen(2) call until client is ready, to limit initial
connection spike.

XXX: I still miss an unlisten(2).

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2658 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_acceptor.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt_child.c

index 5dfd39b3736bd1f0d37a1fd685469e00f59d2d5a..f17d49960dbbf91bb8d24cfabf3b15f0b3c6b627 100644 (file)
@@ -161,6 +161,9 @@ vca_acct(void *arg)
        AN(pfd);
        i = 0;
        VTAILQ_FOREACH(ls, &heritage.socks, list) {
+               if (ls->sock < 0)
+                       continue;
+               AZ(listen(ls->sock, params->listen_depth));
                AZ(setsockopt(ls->sock, SOL_SOCKET, SO_LINGER,
                    &linger, sizeof linger));
                pfd[i].events = POLLIN;
index 374e2f88727cc414145fc6f2db056542d2768ea2..74542a1e56a8c8666dae3b8dbc74b3b1fff07240 100644 (file)
@@ -38,6 +38,8 @@
 struct listen_sock {
        VTAILQ_ENTRY(listen_sock)       list;
        int                             sock;
+       char                            *hname;
+       char                            *pname;
        struct vss_addr                 *addr;
 };
 
index 7b88d3048d5260be7e58c58f33fc09a0b6d9da6a..f4fa67ce124a5b8dc8d5189d3ebc9de23210c004 100644 (file)
@@ -138,18 +138,21 @@ open_sockets(void)
 {
        struct listen_sock *ls, *ls2;
        int good = 0;
+       char hbuf[TCP_ADDRBUFSIZE];
+       char pbuf[TCP_PORTBUFSIZE];
 
        VTAILQ_FOREACH_SAFE(ls, &heritage.socks, list, ls2) {
                if (ls->sock >= 0) {
                        good++;
                        continue;
                }
-               ls->sock = VSS_listen(ls->addr, params->listen_depth);
-               if (ls->sock < 0) {
-                       VTAILQ_REMOVE(&heritage.socks, ls, list);
-                       free(ls);
+               ls->sock = VSS_bind(ls->addr);
+               if (ls->sock < 0) 
                        continue;
-               }
+
+               TCP_myname(ls->sock, hbuf, sizeof hbuf, pbuf, sizeof pbuf);
+               REPLACE(ls->hname, hbuf);
+               REPLACE(ls->pname, pbuf);
                /*
                 * Set nonblocking mode to avoid a race where a client
                 * closes before we call accept(2) and nobody else are in
@@ -174,8 +177,10 @@ close_sockets(void)
        VTAILQ_FOREACH(ls, &heritage.socks, list) {
                if (ls->sock < 0)
                        continue;
-               (void)close(ls->sock);
+               AZ(close(ls->sock));
                ls->sock = -1;
+               REPLACE(ls->hname, NULL);
+               REPLACE(ls->pname, NULL);
        }
 }