r4774 - in trunk/varnish-cache: bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishtop include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Thu May 6 10:26:50 CEST 2010


Author: phk
Date: 2010-05-06 10:26:49 +0200 (Thu, 06 May 2010)
New Revision: 4774

Modified:
   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/varnishtop/varnishtop.c
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
Centralize the '-n' option handling for the log tools in libvarnishapi.



Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c
===================================================================
--- trunk/varnish-cache/bin/varnishhist/varnishhist.c	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/bin/varnishhist/varnishhist.c	2010-05-06 08:26:49 UTC (rev 4774)
@@ -320,15 +320,11 @@
 {
 	int o;
 	struct VSL_data *vd;
-	const char *n_arg = NULL;
 
 	vd = VSL_New();
 
-	while ((o = getopt(argc, argv, VSL_ARGS "n:Vw:")) != -1) {
+	while ((o = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) {
 		switch (o) {
-		case 'n':
-			n_arg = optarg;
-			break;
 		case 'V':
 			varnish_version("varnishhist");
 			exit(0);
@@ -342,7 +338,7 @@
 		}
 	}
 
-	if (VSL_OpenLog(vd, n_arg))
+	if (VSL_OpenLog(vd))
 		exit(1);
 
 	log_ten = log(10.0);

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2010-05-06 08:26:49 UTC (rev 4774)
@@ -311,7 +311,6 @@
 {
 	int c;
 	int a_flag = 0, D_flag = 0, o_flag = 0, u_flag = 0;
-	const char *n_arg = NULL;
 	const char *P_arg = NULL;
 	const char *w_arg = NULL;
 	struct pidfh *pfh = NULL;
@@ -319,7 +318,7 @@
 
 	vd = VSL_New();
 
-	while ((c = getopt(argc, argv, VSL_ARGS "aDon:P:uVw:")) != -1) {
+	while ((c = getopt(argc, argv, VSL_ARGS "aDoP:uVw:")) != -1) {
 		switch (c) {
 		case 'a':
 			a_flag = 1;
@@ -335,9 +334,6 @@
 		case 'D':
 			D_flag = 1;
 			break;
-		case 'n':
-			n_arg = optarg;
-			break;
 		case 'o':
 			o_flag = 1;
 			break;
@@ -363,7 +359,7 @@
 	if (o_flag && w_arg != NULL)
 		usage();
 
-	if (VSL_OpenLog(vd, n_arg))
+	if (VSL_OpenLog(vd))
 		exit(1);
 
 	if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) {

Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-05-06 08:26:49 UTC (rev 4774)
@@ -521,7 +521,6 @@
 {
 	int c;
 	int a_flag = 0, D_flag = 0;
-	const char *n_arg = NULL;
 	const char *P_arg = NULL;
 	const char *w_arg = NULL;
 	struct pidfh *pfh = NULL;
@@ -530,7 +529,7 @@
 
 	vd = VSL_New();
 
-	while ((c = getopt(argc, argv, VSL_ARGS "aDn:P:Vw:f")) != -1) {
+	while ((c = getopt(argc, argv, VSL_ARGS "aDP:Vw:f")) != -1) {
 		switch (c) {
 		case 'a':
 			a_flag = 1;
@@ -541,9 +540,6 @@
 		case 'D':
 			D_flag = 1;
 			break;
-		case 'n':
-			n_arg = optarg;
-			break;
 		case 'P':
 			P_arg = optarg;
 			break;
@@ -569,7 +565,7 @@
 
 	VSL_Arg(vd, 'c', optarg);
 
-	if (VSL_OpenLog(vd, n_arg))
+	if (VSL_OpenLog(vd))
 		exit(1);
 
 	if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) {

Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c
===================================================================
--- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c	2010-05-06 08:26:49 UTC (rev 4774)
@@ -724,7 +724,7 @@
 	debug = 0;
 
 	VSL_Arg(vd, 'c', NULL);
-	while ((c = getopt(argc, argv, "a:Dr:")) != -1) {
+	while ((c = getopt(argc, argv, "a:Dr:n:")) != -1) {
 		switch (c) {
 		case 'a':
 			address = optarg;
@@ -743,7 +743,7 @@
 		usage();
 	}
 
-	if (VSL_OpenLog(vd, NULL))
+	if (VSL_OpenLog(vd))
 		exit(1);
 
 	addr_info = init_connection(address);

Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c
===================================================================
--- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c	2010-05-06 08:26:49 UTC (rev 4774)
@@ -321,15 +321,11 @@
 {
 	int o;
 	struct VSL_data *vd;
-	const char *n_arg = NULL;
 
 	vd = VSL_New();
 
-	while ((o = getopt(argc, argv, VSL_ARGS "n:Vw:")) != -1) {
+	while ((o = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) {
 		switch (o) {
-		case 'n':
-			n_arg = optarg;
-			break;
 		case 'V':
 			varnish_version("varnishsizes");
 			exit(0);
@@ -343,7 +339,7 @@
 		}
 	}
 
-	if (VSL_OpenLog(vd, n_arg))
+	if (VSL_OpenLog(vd))
 		exit(1);
 
 	log_ten = log(10.0);

Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c	2010-05-06 08:26:49 UTC (rev 4774)
@@ -302,20 +302,16 @@
 main(int argc, char **argv)
 {
 	struct VSL_data *vd;
-	const char *n_arg = NULL;
 	int o, once = 0;
 
 	vd = VSL_New();
 
-	while ((o = getopt(argc, argv, VSL_ARGS "1fn:V")) != -1) {
+	while ((o = getopt(argc, argv, VSL_ARGS "1fV")) != -1) {
 		switch (o) {
 		case '1':
 			VSL_Arg(vd, 'd', NULL);
 			once = 1;
 			break;
-		case 'n':
-			n_arg = optarg;
-			break;
 		case 'f':
 			f_flag = 1;
 			break;
@@ -329,7 +325,7 @@
 		}
 	}
 
-	if (VSL_OpenLog(vd, n_arg))
+	if (VSL_OpenLog(vd))
 		exit (1);
 
 	if (once) {

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/include/varnishapi.h	2010-05-06 08:26:49 UTC (rev 4774)
@@ -43,14 +43,14 @@
     unsigned len, unsigned spec, const char *ptr);
 #define VSL_S_CLIENT	(1 << 0)
 #define VSL_S_BACKEND	(1 << 1)
-#define VSL_ARGS	"bCcdI:i:k:r:s:X:x:"
+#define VSL_ARGS	"bCcdI:i:k:n:r:s:X:x:"
 #define VSL_USAGE	"[-bCcd] [-i tag] [-I regexp] [-k keep]" \
 			" [-r file] [-s skip] [-X regexp] [-x tag]"
 vsl_handler VSL_H_Print;
 struct VSL_data;
 struct VSL_data *VSL_New(void);
 void VSL_Select(struct VSL_data *vd, unsigned tag);
-int VSL_OpenLog(struct VSL_data *vd, const char *varnish_name);
+int VSL_OpenLog(struct VSL_data *vd);
 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);

Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2010-05-05 09:34:20 UTC (rev 4773)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2010-05-06 08:26:49 UTC (rev 4774)
@@ -69,6 +69,7 @@
 	unsigned		rbuflen;
 	unsigned char		*rbuf;
 
+	char			*n_opt;
 	int			b_opt;
 	int			c_opt;
 	int			d_opt;
@@ -201,7 +202,7 @@
 /*--------------------------------------------------------------------*/
 
 int
-VSL_OpenLog(struct VSL_data *vd, const char *varnish_name)
+VSL_OpenLog(struct VSL_data *vd)
 {
 	unsigned char *p;
 
@@ -209,7 +210,7 @@
 	if (vd->fd != -1)
 		return (0);
 
-	if (vsl_shmem_map(varnish_name))
+	if (vsl_shmem_map(vd->n_opt))
 		return (-1);
 
 	vd->head = vsl_lh;
@@ -562,6 +563,11 @@
 		vd->flags |= F_NON_BLOCKING;
 		return (1);
 	case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg));
+	case 'n':
+		free(vd->n_opt);
+		vd->n_opt = strdup(opt);
+		assert(vd->n_opt != NULL);
+		return (1);
 	case 'r': return (vsl_r_arg(vd, opt));
 	case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg));
 	case 'C': vd->regflags = VRE_CASELESS; return (1);




More information about the varnish-commit mailing list