r1012 - trunk/varnish-cache/bin/varnishncsa

des at projects.linpro.no des at projects.linpro.no
Sat Sep 16 14:28:34 CEST 2006


Author: des
Date: 2006-09-16 14:28:34 +0200 (Sat, 16 Sep 2006)
New Revision: 1012

Modified:
   trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
Log:
Add the ability to write to a file (it was previously documented but not
implemented).
Fix the usage string.

Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2006-09-16 12:26:45 UTC (rev 1011)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2006-09-16 12:28:34 UTC (rev 1012)
@@ -160,7 +160,7 @@
 static void
 usage(void)
 {
-	fprintf(stderr, "usage: varnishncsa [-V] [-w file] [-r file]\n");
+	fprintf(stderr, "usage: varnishncsa %s [-aV] [-w file]\n", VSL_ARGS);
 	exit(1);
 }
 
@@ -169,32 +169,52 @@
 {
 	int i, c;
 	struct VSL_data *vd;
+	const char *ofn = NULL;
+	FILE *of = stdout;
+	int append = 0;
 
 	vd = VSL_New();
 	
-	while ((c = getopt(argc, argv, VSL_ARGS "")) != -1) {
+	while ((c = getopt(argc, argv, VSL_ARGS "aVw:")) != -1) {
 		i = VSL_Arg(vd, c, optarg);
 		if (i < 0)
 			exit (1);
 		if (i > 0)
 			continue;
 		switch (c) {
+		case 'a':
+			append = 1;
+			break;
 		case 'V':
 			varnish_version("varnishncsa");
 			exit(0);
+		case 'w':
+			ofn = optarg;
+			break;
 		default:
+			if (VSL_Arg(vd, c, optarg) > 0)
+				break;
 			usage();
 		}
 	}
 
 	if (VSL_OpenLog(vd))
-		exit (1);
+		exit(1);
 
-	while (1) {
-		i = VSL_Dispatch(vd, extended_log_format, stdout);
-		if (i < 0)
-			break;
+	if (ofn && (of = fopen(ofn, append ? "a" : "w")) == NULL) {
+		perror(ofn);
+		exit(1);
+	} else {
+		ofn = "stdout";
 	}
-	return (0);
+
+	while (VSL_Dispatch(vd, extended_log_format, of) == 0) {
+		if (fflush(of) != 0) {
+			perror(ofn);
+			exit(1);
+		}
+	}
+
+	exit(0);
 }
 




More information about the varnish-commit mailing list