r4909 - in trunk/varnish-cache: bin/varnishadm bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishstat bin/varnishtest bin/varnishtop include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Sat Jun 5 22:17:36 CEST 2010


Author: phk
Date: 2010-06-05 22:17:36 +0200 (Sat, 05 Jun 2010)
New Revision: 4909

Modified:
   trunk/varnish-cache/bin/varnishadm/varnishadm.c
   trunk/varnish-cache/bin/varnishhist/varnishhist.c
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
   trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
   trunk/varnish-cache/bin/varnishreplay/varnishreplay.c
   trunk/varnish-cache/bin/varnishsizes/varnishsizes.c
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
   trunk/varnish-cache/bin/varnishtop/varnishtop.c
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
Log:
Split VSL_Arg() into VSL_Log_Arg() and VSL_Stat_Arg()



Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c
===================================================================
--- trunk/varnish-cache/bin/varnishadm/varnishadm.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishadm/varnishadm.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -244,7 +244,7 @@
 
 	if (n_arg != NULL) {
 		vsd = VSL_New();
-		assert(VSL_Arg(vsd, 'n', n_arg));
+		assert(VSL_Log_Arg(vsd, 'n', n_arg));
 		if (!VSL_Open(vsd)) {
 			if (T_arg == NULL) {
 				p = VSL_Find_Alloc(vsd, "Arg", "-T", "", NULL);

Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c
===================================================================
--- trunk/varnish-cache/bin/varnishhist/varnishhist.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishhist/varnishhist.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -332,7 +332,7 @@
 			delay = atoi(optarg);
 			break;
 		default:
-			if (VSL_Arg(vd, o, optarg) > 0)
+			if (VSL_Log_Arg(vd, o, optarg) > 0)
 				break;
 			usage();
 		}

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -325,11 +325,11 @@
 			break;
 		case 'b':
 			b_flag = 1;
-			VSL_Arg(vd, c, optarg);
+			VSL_Log_Arg(vd, c, optarg);
 			break;
 		case 'c':
 			c_flag = 1;
-			VSL_Arg(vd, c, optarg);
+			VSL_Log_Arg(vd, c, optarg);
 			break;
 		case 'D':
 			D_flag = 1;
@@ -350,7 +350,7 @@
 			w_arg = optarg;
 			break;
 		default:
-			if (VSL_Arg(vd, c, optarg) > 0)
+			if (VSL_Log_Arg(vd, c, optarg) > 0)
 				break;
 			usage();
 		}

Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -557,13 +557,13 @@
 			/* XXX: Silently ignored: it's required anyway */
 			break;
 		default:
-			if (VSL_Arg(vd, c, optarg) > 0)
+			if (VSL_Log_Arg(vd, c, optarg) > 0)
 				break;
 			usage();
 		}
 	}
 
-	VSL_Arg(vd, 'c', optarg);
+	VSL_Log_Arg(vd, 'c', optarg);
 
 	if (VSL_OpenLog(vd))
 		exit(1);

Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c
===================================================================
--- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -723,7 +723,7 @@
 	vd = VSL_New();
 	debug = 0;
 
-	VSL_Arg(vd, 'c', NULL);
+	VSL_Log_Arg(vd, 'c', NULL);
 	while ((c = getopt(argc, argv, "a:Dr:n:")) != -1) {
 		switch (c) {
 		case 'a':
@@ -733,7 +733,7 @@
 			++debug;
 			break;
 		default:
-			if (VSL_Arg(vd, c, optarg) > 0)
+			if (VSL_Log_Arg(vd, c, optarg) > 0)
 				break;
 			usage();
 		}

Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c
===================================================================
--- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -333,7 +333,7 @@
 			delay = atoi(optarg);
 			break;
 		default:
-			if (VSL_Arg(vd, o, optarg) > 0)
+			if (VSL_Log_Arg(vd, o, optarg) > 0)
 				break;
 			usage();
 		}

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -296,7 +296,7 @@
 			xml = 1;
 			break;
 		default:
-			if (VSL_Arg(vd, c, optarg) > 0)
+			if (VSL_Stat_Arg(vd, c, optarg) > 0)
 				break;
 			usage();
 		}

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -364,7 +364,7 @@
 
 	if (v->stats != NULL)
 		VSL_Close(v->vd);
-	(void)VSL_Arg(v->vd, 'n', v->workdir);
+	(void)VSL_Log_Arg(v->vd, 'n', v->workdir);
 	v->stats = VSL_OpenStats(v->vd);
 }
 

Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -309,7 +309,7 @@
 	while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) {
 		switch (o) {
 		case '1':
-			VSL_Arg(vd, 'd', NULL);
+			VSL_Log_Arg(vd, 'd', NULL);
 			once = 1;
 			break;
 		case 'f':
@@ -319,7 +319,7 @@
 			varnish_version("varnishtop");
 			exit(0);
 		default:
-			if (VSL_Arg(vd, o, optarg) > 0)
+			if (VSL_Log_Arg(vd, o, optarg) > 0)
 				break;
 			usage();
 		}

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/include/varnishapi.h	2010-06-05 20:17:36 UTC (rev 4909)
@@ -55,7 +55,8 @@
 void VSL_NonBlocking(struct VSL_data *vd, int nb);
 int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv);
 int VSL_NextLog(struct VSL_data *lh, unsigned char **pp);
-int VSL_Arg(struct VSL_data *vd, int arg, const char *opt);
+int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt);
+int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt);
 void VSL_Close(struct VSL_data *vd);
 int VSL_Open(struct VSL_data *vd);
 void VSL_Delete(struct VSL_data *vd);

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c	2010-06-05 15:14:43 UTC (rev 4908)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c	2010-06-05 20:17:36 UTC (rev 4909)
@@ -167,6 +167,7 @@
 	}
 	return (1);
 }
+
 /*--------------------------------------------------------------------*/
 
 static int
@@ -187,15 +188,26 @@
 	return (1);
 }
 
-/*--------------------------------------------------------------------
- * XXX: Should really be split into three:
- *   VSL_Arg() for generic args for all programs (-n)
- *   VSL_Log_Arg() for log readers.
- *   VSL_Stat_Arg() for stat reporters.
- */
+/*--------------------------------------------------------------------*/
 
+static int
+vsl_n_arg(struct VSL_data *vd, const char *opt)
+{
+
+	REPLACE(vd->n_opt, opt);
+	AN(vd->n_opt);
+	if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) {
+		fprintf(stderr, "Invalid instance name: %s\n",
+		    strerror(errno));
+		return (-1);
+	}
+	return (1);
+}
+
+/*--------------------------------------------------------------------*/
+
 int
-VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
+VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt)
 {
 
 	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
@@ -208,16 +220,7 @@
 		return (1);
 	case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg));
 	case 'k': return (vsl_k_arg(vd, opt));
-	case 'n':
-		free(vd->n_opt);
-		vd->n_opt = strdup(opt);
-		assert(vd->n_opt != NULL);
-		if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) {
-			fprintf(stderr, "Invalid instance name: %s\n",
-			    strerror(errno));
-			return (-1);
-		}
-		return (1);
+	case 'n': return (vsl_n_arg(vd, opt));
 	case 'r': return (vsl_r_arg(vd, opt));
 	case 's': return (vsl_s_arg(vd, opt));
 	case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg));
@@ -236,3 +239,17 @@
 		return (0);
 	}
 }
+
+/*--------------------------------------------------------------------*/
+
+int
+VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	switch (arg) {
+	case 'n': return (vsl_n_arg(vd, opt));
+	default:
+		return (0);
+	}
+}




More information about the varnish-commit mailing list