r2400 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Jan 29 12:53:41 CET 2008


Author: phk
Date: 2008-01-29 12:53:41 +0100 (Tue, 29 Jan 2008)
New Revision: 2400

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_cli.c
Log:
More FlexeLint inspired cleanup


Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c	2008-01-29 11:39:27 UTC (rev 2399)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c	2008-01-29 11:53:41 UTC (rev 2400)
@@ -294,6 +294,24 @@
 };
 
 static int
+mgt_cli_close(const struct cli_port *cp)
+{
+
+	vsb_delete(cp->cli->sb);
+	free(cp->buf);
+	(void)close(cp->fdi);
+	if (cp->fdi == 0)
+		assert(open("/dev/null", O_RDONLY) == 0);
+	(void)close(cp->fdo);
+	if (cp->fdo == 1) {
+		assert(open("/dev/null", O_WRONLY) == 1);
+		(void)close(2);
+		assert(open("/dev/null", O_WRONLY) == 2);
+	}
+	return (1);
+}
+
+static int
 mgt_cli_callback(const struct ev *e, int what)
 {
 	struct cli_port *cp;
@@ -303,7 +321,7 @@
 	CAST_OBJ_NOTNULL(cp, e->priv, CLI_PORT_MAGIC);
 
 	if (what & (EV_ERR | EV_HUP | EV_GONE))
-		goto cli_close;
+		return (mgt_cli_close(cp));
 
 	/* grow the buffer if it is full */
 	if (cp->nbuf == cp->lbuf) {
@@ -315,7 +333,7 @@
 	/* read more data into the buffer */
 	i = read(cp->fdi, cp->buf + cp->nbuf, cp->lbuf - cp->nbuf);
 	if (i <= 0)
-		goto cli_close;
+		return (mgt_cli_close(cp));
 	cp->nbuf += i;
 
 	for (p = q = cp->buf; q < cp->buf + cp->nbuf; ++q) {
@@ -330,7 +348,7 @@
 
 		/* send the result back */
 		if (cli_writeres(cp->fdo, cp->cli))
-			goto cli_close;
+			return (mgt_cli_close(cp));
 
 		/* ready for next command */
 		p = q + 1;
@@ -344,21 +362,6 @@
 	} else
 		cp->nbuf = 0;
 	return (0);
-
-cli_close:
-	vsb_delete(cp->cli->sb);
-	free(cp->buf);
-	(void)close(cp->fdi);
-	if (cp->fdi == 0)
-		assert(open("/dev/null", O_RDONLY) == 0);
-	(void)close(cp->fdo);
-	if (cp->fdo == 1) {
-		assert(open("/dev/null", O_WRONLY) == 1);
-		close(2);
-		assert(open("/dev/null", O_WRONLY) == 2);
-	}
-	free(cp);
-	return (1);
 }
 
 void
@@ -389,7 +392,7 @@
 	cp->ev->fd_flags = EV_RD;
 	cp->ev->callback = mgt_cli_callback;
 	cp->ev->priv = cp;
-	ev_add(mgt_evb, cp->ev);
+	AZ(ev_add(mgt_evb, cp->ev));
 }
 
 static int
@@ -417,7 +420,7 @@
 	int i, n;
 
 	XXXAZ(VSS_parse(T_arg, &addr, &port));
-	XXXAN(n = VSS_resolve(addr, port, &ta));
+	n = VSS_resolve(addr, port, &ta);
 	free(addr);
 	free(port);
 	if (n == 0) {
@@ -431,7 +434,7 @@
 		ev->fd = sock;
 		ev->fd_flags = POLLIN;
 		ev->callback = telnet_accept;
-		ev_add(mgt_evb, ev);
+		AZ(ev_add(mgt_evb, ev));
 		free(ta[i]);
 		ta[i] = NULL;
 	}




More information about the varnish-commit mailing list