Mailing List Archive

r2659 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-06-09 15:35:35 +0200 (Mon, 09 Jun 2008)
New Revision: 2659

Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt_child.c
trunk/varnish-cache/bin/varnishd/mgt_param.c
Log:
Slight backtracking: Store the specified socket name in the listen socket
structure, instead of whatever we actually bound to. It is more informative
and intuitive.

Report the listen socket spec in the SessionOpen shm record.

Close listen sockets as soon as we have forked the child, this eliminated
a fd-leak when a socket was eliminated from listen_address while the child
ran.

Fix various potential problems related to not being able to bind to one
or more listen addresses.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2008-06-09 13:11:45 UTC (rev 2658)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2008-06-09 13:35:35 UTC (rev 2659)
@@ -319,6 +319,7 @@
socklen_t mysockaddrlen;
struct sockaddr *sockaddr;
struct sockaddr *mysockaddr;
+ struct listen_sock *mylsock;

/* formatted ascii client address */
char *addr;

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-06-09 13:11:45 UTC (rev 2658)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-06-09 13:35:35 UTC (rev 2659)
@@ -119,7 +119,8 @@
addr, sizeof addr, port, sizeof port);
sp->addr = WS_Dup(sp->ws, addr);
sp->port = WS_Dup(sp->ws, port);
- VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port);
+ VSL(SLT_SessionOpen, sp->fd, "%s %s %s",
+ sp->addr, sp->port, sp->mylsock->name);
sp->acct.first = sp->t_open;
if (need_test)
sock_test(sp->fd);
@@ -194,16 +195,19 @@
#endif
i = poll(pfd, heritage.nsocks, 1000);
now = TIM_real();
- for (u = 0; u < heritage.nsocks; u++) {
- if (pfd[u].revents == 0)
+ u = 0;
+ VTAILQ_FOREACH(ls, &heritage.socks, list) {
+ if (ls->sock < 0)
continue;
+ if (pfd[u++].revents == 0)
+ continue;
VSL_stats->client_conn++;
l = sizeof addr_s;
addr = (void*)&addr_s;
- i = accept(pfd[u].fd, addr, &l);
+ i = accept(ls->sock, addr, &l);
if (i < 0) {
if (errno != EAGAIN && errno != ECONNABORTED) {
- VSL(SLT_Debug, pfd[u].fd,
+ VSL(SLT_Debug, ls->sock,
"Accept failed errno=%d", errno);
/* XXX: stats ? */
}
@@ -215,6 +219,7 @@
sp->fd = i;
sp->id = i;
sp->t_open = now;
+ sp->mylsock = ls;

sp->step = STP_FIRST;
WRK_QueueSession(sp);

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2008-06-09 13:11:45 UTC (rev 2658)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-06-09 13:35:35 UTC (rev 2659)
@@ -38,8 +38,7 @@
struct listen_sock {
VTAILQ_ENTRY(listen_sock) list;
int sock;
- char *hname;
- char *pname;
+ char *name;
struct vss_addr *addr;
};


Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-06-09 13:11:45 UTC (rev 2658)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-06-09 13:35:35 UTC (rev 2659)
@@ -138,8 +138,6 @@
{
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) {
@@ -150,9 +148,6 @@
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
@@ -179,8 +174,6 @@
continue;
AZ(close(ls->sock));
ls->sock = -1;
- REPLACE(ls->hname, NULL);
- REPLACE(ls->pname, NULL);
}
}

@@ -213,6 +206,7 @@
exit(1);
}
if (pid == 0) {
+ /* XXX: We should close things like syslog & telnet sockets */
if (geteuid() == 0) {
XXXAZ(setgid(params->gid));
XXXAZ(setuid(params->uid));
@@ -240,6 +234,8 @@

fprintf(stderr, "start child pid %jd\n", (intmax_t)pid);

+ close_sockets();
+
AZ(close(child_fds[1]));
child_fds[1] = -1;

@@ -292,7 +288,6 @@
if (child_state != CH_RUNNING)
return;

- close_sockets();
child_state = CH_STOPPING;

if (ev_poker != NULL) {
@@ -365,7 +360,6 @@
if (child_state == CH_DIED && params->auto_restart)
start_child();
else if (child_state == CH_DIED) {
- close_sockets();
child_state = CH_STOPPED;
} else if (child_state == CH_STOPPING)
child_state = CH_STOPPED;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-06-09 13:11:45 UTC (rev 2658)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-06-09 13:35:35 UTC (rev 2659)
@@ -299,6 +299,7 @@

VTAILQ_FOREACH_SAFE(ls, lsh, list, ls2) {
VTAILQ_REMOVE(lsh, ls, list);
+ free(ls->name);
free(ls->addr);
free(ls);
}
@@ -359,6 +360,8 @@
AN(ls);
ls->sock = -1;
ls->addr = ta[j];
+ ls->name = strdup(av[i]);
+ AN(ls->name);
VTAILQ_INSERT_TAIL(&lsh, ls, list);
}
free(ta);