]> err.no Git - varnish/commitdiff
Add the ability to write to a file (it was previously documented but not
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 16 Sep 2006 12:28:34 +0000 (12:28 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 16 Sep 2006 12:28:34 +0000 (12:28 +0000)
implemented).
Fix the usage string.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1012 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishncsa/varnishncsa.c

index f5608bafd451bd69c55588cd823d8883246e557a..2db61872e60d91f109ae1a4a14b999669b0c06d1 100644 (file)
@@ -160,7 +160,7 @@ extended_log_format(void *priv, unsigned tag, unsigned fd, unsigned len, unsigne
 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 @@ main(int argc, char **argv)
 {
        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);
 }