]> err.no Git - varnish/commitdiff
Add a -a option to control append / overwrite when writing to a file.
authordes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 16 Sep 2006 12:26:45 +0000 (12:26 +0000)
committerdes <des@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 16 Sep 2006 12:26:45 +0000 (12:26 +0000)
Fix the usage string.

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

varnish-cache/bin/varnishlog/varnishlog.c

index c290ed799bf8b38caa909a5a6d515bb61f6a8e50..e7a312cb46d303e528294187272704b7f9514247 100644 (file)
@@ -174,15 +174,16 @@ do_order(struct VSL_data *vd, int argc, char **argv)
 /*--------------------------------------------------------------------*/
 
 static void
-do_write(struct VSL_data *vd, const char *w_opt)
+do_write(struct VSL_data *vd, const char *w_opt, int a_flag)
 {
-       int fd, i;
+       int fd, flags, i;
        unsigned char *p;
 
+       flags = (a_flag ? O_APPEND : O_TRUNC) | O_WRONLY | O_CREAT;
        if (!strcmp(w_opt, "-"))
                fd = STDOUT_FILENO;
        else
-               fd = open(w_opt, O_WRONLY|O_APPEND|O_CREAT, 0644);
+               fd = open(w_opt, flags, 0644);
        if (fd < 0) {
                perror(w_opt);
                exit (1);
@@ -208,7 +209,7 @@ static void
 usage(void)
 {
        fprintf(stderr,
-           "usage: varnishlog [(stdopts)] [-oV] [-w file] [-r file]\n");
+           "usage: varnishlog %s [-aoV] [-w file]\n", VSL_USAGE);
        exit(1);
 }
 
@@ -216,14 +217,17 @@ int
 main(int argc, char **argv)
 {
        int i, c;
-       int o_flag = 0;
+       int a_flag = 0, o_flag = 0;
        char *w_opt = NULL;
        struct VSL_data *vd;
 
        vd = VSL_New();
        
-       while ((c = getopt(argc, argv, VSL_ARGS "oVw:")) != -1) {
+       while ((c = getopt(argc, argv, VSL_ARGS "aoVw:")) != -1) {
                switch (c) {
+               case 'a':
+                       a_flag = 1;
+                       break;
                case 'o':
                        o_flag = 1;
                        break;
@@ -257,7 +261,7 @@ main(int argc, char **argv)
                exit (1);
 
        if (w_opt != NULL) 
-               do_write(vd, w_opt);
+               do_write(vd, w_opt, a_flag);
 
        if (o_flag)
                do_order(vd, argc - optind, argv + optind);