]> err.no Git - varnish/commitdiff
renovate tackle_warg()
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Jul 2008 09:57:11 +0000 (09:57 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 22 Jul 2008 09:57:11 +0000 (09:57 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2989 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/varnishd.c

index bb23d99d1a0adf83cdb277351277f51bb6871867..10b742d9a6c82a9bc321d725d6242ea151172667 100644 (file)
@@ -98,6 +98,19 @@ pick(const struct choice *cp, const char *which, const char *kind)
 
 /*--------------------------------------------------------------------*/
 
+static unsigned long
+arg_ul(const char *p)
+{
+       char *q;
+       unsigned long ul;
+
+       ul = strtoul(p, &q, 0);
+       if (*q != '\0')
+               ARGV_ERR("Invalid number: \"%s\"\n", p);
+       return (ul);
+}
+
+/*--------------------------------------------------------------------*/
 extern struct stevedore sma_stevedore;
 extern struct stevedore smf_stevedore;
 
@@ -224,47 +237,35 @@ usage(void)
 static void
 tackle_warg(const char *argv)
 {
+       char **av;
        unsigned int u;
-       char *ep, *eq;
 
-       u = strtoul(argv, &ep, 0);
-       if (ep == argv)
-               usage();
-       while (isspace(*ep))
-               ep++;
-       if (u < 1)
-               usage();
-       params->wthread_min = u;
+       av = ParseArgv(argv, ARGV_COMMA);
+       AN(av);
 
-       if (*ep == '\0') {
-               params->wthread_max = params->wthread_min;
-               return;
-       }
+       if (av[0] != NULL) 
+               ARGV_ERR("%s\n", av[0]);
 
-       if (*ep != ',')
-               usage();
-       u = strtoul(++ep, &eq, 0);
-       if (eq == ep)
+       if (av[1] == NULL) 
                usage();
-       if (u < params->wthread_min)
+
+       u = arg_ul(av[1]);
+       if (u < 1)
                usage();
-       while (isspace(*eq))
-               eq++;
-       params->wthread_max = u;
+       params->wthread_max = params->wthread_min = u;
 
-       if (*eq == '\0')
-               return;
+       if (av[2] != NULL) {
+               u = arg_ul(av[2]);
+               if (u < params->wthread_min)
+                       usage();
+               params->wthread_max = u;
 
-       if (*eq != ',')
-               usage();
-       u = strtoul(++eq, &ep, 0);
-       if (ep == eq)
-               usage();
-       while (isspace(*ep))
-               ep++;
-       if (*ep != '\0')
-               usage();
-       params->wthread_timeout = u;
+               if (av[3] != NULL) {
+                       u = arg_ul(av[3]);
+                       params->wthread_timeout = u;
+               }
+       }
+       FreeArgv(av);
 }
 
 /*--------------------------------------------------------------------