[master] 89a3f0e Use closefd() throughout, take 3

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Feb 21 15:51:05 CET 2017


commit 89a3f0ee213772162ce9eabd437c1701c9398c75
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Feb 21 15:48:09 2017 +0100

    Use closefd() throughout, take 3
    
    New semantic patch, follow-up to 6db7d75:
    
        @@
        expression fd;
        @@
    
         closefd(&fd);
        -fd = -1;
    
    Spotted by phk.

diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 54ec8b8..7c5a7a0 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -483,7 +483,6 @@ varnish_launch(struct varnish *v)
 	nfd = accept(v->cli_fd, NULL, NULL);
 	if (nfd < 0) {
 		closefd(&v->cli_fd);
-		v->cli_fd = -1;
 		vtc_fatal(v->vl, "FAIL no CLI connection accepted");
 	}
 
@@ -620,7 +619,6 @@ varnish_cleanup(struct varnish *v)
 
 	/* Close the CLI connection */
 	closefd(&v->cli_fd);
-	v->cli_fd = -1;
 
 	/* Close the STDIN connection. */
 	closefd(&v->fds[1]);
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index 250bdab..ae0ace8 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -240,7 +240,6 @@ VSM_Open(struct VSM_data *vd)
 	AZ(fstat(vd->vsm_fd, &vd->fstat));
 	if (!S_ISREG(vd->fstat.st_mode)) {
 		closefd(&vd->vsm_fd);
-		vd->vsm_fd = -1;
 		return (vsm_diag(vd, "%s is not a regular file",
 		    vd->fname));
 	}
@@ -248,20 +247,17 @@ VSM_Open(struct VSM_data *vd)
 	i = read(vd->vsm_fd, &slh, sizeof slh);
 	if (i != sizeof slh) {
 		closefd(&vd->vsm_fd);
-		vd->vsm_fd = -1;
 		return (vsm_diag(vd, "Cannot read %s: %s",
 		    vd->fname, strerror(errno)));
 	}
 
 	if (memcmp(slh.marker, VSM_HEAD_MARKER, sizeof slh.marker)) {
 		closefd(&vd->vsm_fd);
-		vd->vsm_fd = -1;
 		return (vsm_diag(vd, "Not a VSM file %s", vd->fname));
 	}
 
 	if (!vd->N_opt && slh.alloc_seq == 0) {
 		closefd(&vd->vsm_fd);
-		vd->vsm_fd = -1;
 		return (vsm_diag(vd,
 		    "Abandoned VSM file (Varnish not running?) %s",
 		    vd->fname));
@@ -271,7 +267,6 @@ VSM_Open(struct VSM_data *vd)
 	    PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsm_fd, 0);
 	if (v == MAP_FAILED) {
 		closefd(&vd->vsm_fd);
-		vd->vsm_fd = -1;
 		return (vsm_diag(vd, "Cannot mmap %s: %s",
 		    vd->fname, strerror(errno)));
 	}
@@ -311,7 +306,6 @@ VSM_Close(struct VSM_data *vd)
 	vd->e = NULL;
 	vd->head = NULL;
 	closefd(&vd->vsm_fd);
-	vd->vsm_fd = -1;
 }
 
 /*--------------------------------------------------------------------*/



More information about the varnish-commit mailing list