[master] 6dca812 More consistent error messages

Federico G. Schwindt fgsch at lodoss.net
Sun Dec 4 11:51:04 CET 2016


commit 6dca81266c00dd3b2f737b1cad10e4570b0ccbce
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Sun Dec 4 10:49:08 2016 +0000

    More consistent error messages
    
    In particular VSL_Error() and VSM_Error() return a string without the
    newline now.

diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c
index dde6ead..c5d9d92 100644
--- a/bin/varnishlog/varnishlog.c
+++ b/bin/varnishlog/varnishlog.c
@@ -83,7 +83,7 @@ openout(int append)
 	else
 		LOG.fo = VSL_WriteOpen(VUT.vsl, LOG.w_arg, append, 0);
 	if (LOG.fo == NULL)
-		VUT_Error(2, "Can't open output file (%s)",
+		VUT_Error(2, "Cannot open output file (%s)",
 		    LOG.A_opt ? strerror(errno) : VSL_Error(VUT.vsl));
 	VUT.dispatch_priv = LOG.fo;
 }
diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c
index 33d08e3..2348ad9 100644
--- a/lib/libvarnishapi/vsl_cursor.c
+++ b/lib/libvarnishapi/vsl_cursor.c
@@ -250,18 +250,18 @@ VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, unsigned options)
 
 	if (!VSM_Get(vsm, &vf, VSL_CLASS, "", "")) {
 		(void)vsl_diag(vsl,
-		    "No VSL chunk found (child not started ?)\n");
+		    "No VSL chunk found (child not started ?)");
 		return (NULL);
 	}
 
 	head = vf.b;
 	if (memcmp(head->marker, VSL_HEAD_MARKER, sizeof head->marker)) {
-		(void)vsl_diag(vsl, "Not a VSL chunk\n");
+		(void)vsl_diag(vsl, "Not a VSL chunk");
 		return (NULL);
 	}
 	ALLOC_OBJ(c, VSLC_VSM_MAGIC);
 	if (c == NULL) {
-		(void)vsl_diag(vsl, "Out of memory\n");
+		(void)vsl_diag(vsl, "Out of memory");
 		return (NULL);
 	}
 	c->cursor.priv_tbl = &vslc_vsm_tbl;
@@ -276,7 +276,7 @@ VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, unsigned options)
 
 	i = vslc_vsm_reset(&c->cursor);
 	if (i) {
-		(void)vsl_diag(vsl, "Cursor initialization failure (%d)\n", i);
+		(void)vsl_diag(vsl, "Cursor initialization failure (%d)", i);
 		FREE_OBJ(c);
 		return (NULL);
 	}
@@ -405,7 +405,7 @@ VSL_CursorFile(struct VSL_data *vsl, const char *name, unsigned options)
 	else {
 		fd = open(name, O_RDONLY);
 		if (fd < 0) {
-			vsl_diag(vsl, "Could not open %s: %s\n", name,
+			vsl_diag(vsl, "Cannot open %s: %s", name,
 			    strerror(errno));
 			return (NULL);
 		}
@@ -416,7 +416,7 @@ VSL_CursorFile(struct VSL_data *vsl, const char *name, unsigned options)
 	if (i <= 0) {
 		if (close_fd)
 			(void)close(fd);
-		vsl_diag(vsl, "VSL file read error: %s\n",
+		vsl_diag(vsl, "VSL file read error: %s",
 		    i < 0 ? strerror(errno) : "EOF");
 		return (NULL);
 	}
@@ -424,7 +424,7 @@ VSL_CursorFile(struct VSL_data *vsl, const char *name, unsigned options)
 	if (memcmp(buf, VSL_FILE_ID, sizeof buf)) {
 		if (close_fd)
 			(void)close(fd);
-		vsl_diag(vsl, "Not a VSL file: %s\n", name);
+		vsl_diag(vsl, "Not a VSL file: %s", name);
 		return (NULL);
 	}
 
@@ -432,7 +432,7 @@ VSL_CursorFile(struct VSL_data *vsl, const char *name, unsigned options)
 	if (c == NULL) {
 		if (close_fd)
 			(void)close(fd);
-		vsl_diag(vsl, "Out of memory\n");
+		vsl_diag(vsl, "Out of memory");
 		return (NULL);
 	}
 	c->cursor.priv_tbl = &vslc_file_tbl;
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index 4f614d5..f3fd9f4 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -137,10 +137,10 @@ VSM_n_Arg(struct VSM_data *vd, const char *arg)
 	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 
 	if (vd->head)
-		return (vsm_diag(vd, "VSM_n_Arg: Already open\n"));
+		return (vsm_diag(vd, "VSM_n_Arg: Already open"));
 	if (VIN_N_Arg(arg, &name, NULL, &fname))
-		return (vsm_diag(vd, "Invalid instance name: %s\n",
-			strerror(errno)));
+		return (vsm_diag(vd, "Invalid instance name: %s",
+		    strerror(errno)));
 	AN(name);
 	AN(fname);
 
@@ -165,7 +165,7 @@ VSM_N_Arg(struct VSM_data *vd, const char *arg)
 	AN(arg);
 
 	if (vd->head)
-		return (vsm_diag(vd, "VSM_N_Arg: Already open\n"));
+		return (vsm_diag(vd, "VSM_N_Arg: Already open"));
 	REPLACE(vd->name, arg);
 	REPLACE(vd->fname, arg);
 	vd->N_opt = 1;
@@ -234,14 +234,14 @@ VSM_Open(struct VSM_data *vd)
 
 	vd->vsm_fd = open(vd->fname, O_RDONLY);
 	if (vd->vsm_fd < 0)
-		return (vsm_diag(vd, "Cannot open %s: %s\n",
+		return (vsm_diag(vd, "Cannot open %s: %s",
 		    vd->fname, strerror(errno)));
 
 	AZ(fstat(vd->vsm_fd, &vd->fstat));
 	if (!S_ISREG(vd->fstat.st_mode)) {
 		AZ(close(vd->vsm_fd));
 		vd->vsm_fd = -1;
-		return (vsm_diag(vd, "%s is not a regular file\n",
+		return (vsm_diag(vd, "%s is not a regular file",
 		    vd->fname));
 	}
 
@@ -249,22 +249,22 @@ VSM_Open(struct VSM_data *vd)
 	if (i != sizeof slh) {
 		AZ(close(vd->vsm_fd));
 		vd->vsm_fd = -1;
-		return(vsm_diag(vd, "Cannot read %s: %s\n",
+		return (vsm_diag(vd, "Cannot read %s: %s",
 		    vd->fname, strerror(errno)));
 	}
 
 	if (memcmp(slh.marker, VSM_HEAD_MARKER, sizeof slh.marker)) {
 		AZ(close(vd->vsm_fd));
 		vd->vsm_fd = -1;
-		return (vsm_diag(vd, "Not a VSM file %s\n", vd->fname));
+		return (vsm_diag(vd, "Not a VSM file %s", vd->fname));
 	}
 
 	if (!vd->N_opt && slh.alloc_seq == 0) {
 		AZ(close(vd->vsm_fd));
 		vd->vsm_fd = -1;
 		return (vsm_diag(vd,
-			"Abandoned VSM file (Varnish not running?) %s\n",
-			vd->fname));
+		    "Abandoned VSM file (Varnish not running?) %s",
+		    vd->fname));
 	}
 
 	v = mmap(NULL, slh.shm_size,
@@ -272,7 +272,7 @@ VSM_Open(struct VSM_data *vd)
 	if (v == MAP_FAILED) {
 		AZ(close(vd->vsm_fd));
 		vd->vsm_fd = -1;
-		return (vsm_diag(vd, "Cannot mmap %s: %s\n",
+		return (vsm_diag(vd, "Cannot mmap %s: %s",
 		    vd->fname, strerror(errno)));
 	}
 	vd->head = v;
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index 39c27fb..3d724c4 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -246,15 +246,15 @@ VUT_Setup(void)
 	/* Create and validate the query expression */
 	VUT.vslq = VSLQ_New(VUT.vsl, NULL, VUT.g_arg, VUT.q_arg);
 	if (VUT.vslq == NULL)
-		VUT_Error(1, "Query expression error:\n%s", VSL_Error(VUT.vsl));
+		VUT_Error(1, "Query expression error:\n%s",
+		    VSL_Error(VUT.vsl));
 
 	/* Setup input */
 	if (VUT.r_arg) {
 		REPLACE(VUT.name, VUT.r_arg);
 		c = VSL_CursorFile(VUT.vsl, VUT.r_arg, 0);
 		if (c == NULL)
-			VUT_Error(1, "Can't open log file (%s)",
-			    VSL_Error(VUT.vsl));
+			VUT_Error(1, "%s", VSL_Error(VUT.vsl));
 	} else {
 		VUT.vsm = VSM_New();
 		AN(VUT.vsm);
@@ -276,7 +276,7 @@ VUT_Setup(void)
 				break;
 
 			if (isnan(t_start) && VUT.t_arg > 0.) {
-				VUT_Error(0, "Can't open log -"
+				VUT_Error(0, "Cannot open log -"
 				    " retrying for %.0f seconds", VUT.t_arg);
 				t_start = VTIM_real();
 			}
@@ -293,11 +293,9 @@ VUT_Setup(void)
 
 		if (VUT.t_arg >= 0. && (i || !c)) {
 			if (i)
-				VUT_Error(1, "Can't open VSM file (%s)",
-				    VSM_Error(VUT.vsm));
+				VUT_Error(1, "%s", VSM_Error(VUT.vsm));
 			else
-				VUT_Error(1, "Can't open log (%s)",
-				    VSL_Error(VUT.vsl));
+				VUT_Error(1, "%s", VSL_Error(VUT.vsl));
 		} else if (!isnan(t_start))
 			VUT_Error(0, "Log opened");
 	}



More information about the varnish-commit mailing list