]> granicus.if.org Git - apache/commitdiff
htcacheclean: 19 ways to fail, 1 error message. Fixed.
authorGraham Leggett <minfrin@apache.org>
Fri, 11 Sep 2009 23:57:48 +0000 (23:57 +0000)
committerGraham Leggett <minfrin@apache.org>
Fri, 11 Sep 2009 23:57:48 +0000 (23:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@814091 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
support/htcacheclean.c

diff --git a/CHANGES b/CHANGES
index ca96923d40a1e334e5db8cfcbe31ef8dcc42f634..05b7cd68bdbb15e85ef4004a780cce6acd3f1349 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,8 @@
 
 Changes with Apache 2.3.3
 
+  *) htcacheclean: 19 ways to fail, 1 error message. Fixed. [Graham Leggett]
+
   *) mod_auth_digest: Fail server start when nonce count checking
      is configured without shared memory, or md5-sess algorithm is
      configured. [Dan Poirier]
index d449b6cfae3475a9a7074bffcb6107fc56041bde..b953c72286a0dea3de5a4aca6923b9f4d171e8ad 100644 (file)
@@ -701,9 +701,12 @@ static void purge(char *path, apr_pool_t *pool, apr_off_t max)
  * usage info
  */
 #define NL APR_EOL_STR
-static void usage(void)
+static void usage(const char *error)
 {
-    apr_file_printf(errfile,
+    if (error) {
+       apr_file_printf(errfile, "%s error: %s\n", shortname, error);
+    }
+       apr_file_printf(errfile,
     "%s -- program for cleaning the disk cache."                             NL
     "Usage: %s [-Dvtrn] -pPATH -lLIMIT"                                      NL
     "       %s [-nti] -dINTERVAL -pPATH -lLIMIT"                             NL
@@ -776,6 +779,7 @@ int main(int argc, const char * const argv[])
     intelligent = 0;
     previous = 0; /* avoid compiler warning */
     proxypath = NULL;
+    char errmsg[1024];
 
     if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
         return 1;
@@ -802,48 +806,48 @@ int main(int argc, const char * const argv[])
             break;
         }
         else if (status != APR_SUCCESS) {
-            usage();
+            usage(NULL);
         }
         else {
             switch (opt) {
             case 'i':
                 if (intelligent) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 intelligent = 1;
                 break;
 
             case 'D':
                 if (dryrun) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 dryrun = 1;
                 break;
 
             case 'n':
                 if (benice) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 benice = 1;
                 break;
 
             case 't':
                 if (deldirs) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 deldirs = 1;
                 break;
 
             case 'v':
                 if (verbose) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 verbose = 1;
                 break;
 
             case 'r':
                 if (realclean) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 realclean = 1;
                 deldirs = 1;
@@ -851,7 +855,7 @@ int main(int argc, const char * const argv[])
 
             case 'd':
                 if (isdaemon) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 isdaemon = 1;
                 repeat = apr_atoi64(arg);
@@ -861,7 +865,7 @@ int main(int argc, const char * const argv[])
 
             case 'l':
                 if (limit_found) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 limit_found = 1;
 
@@ -886,44 +890,57 @@ int main(int argc, const char * const argv[])
                         }
                     }
                     if (rv != APR_SUCCESS) {
-                        apr_file_printf(errfile, "Invalid limit: %s"
-                                                 APR_EOL_STR APR_EOL_STR, arg);
-                        usage();
+                        usage(apr_psprintf(pool, "Invalid limit: %s"
+                                                 APR_EOL_STR APR_EOL_STR, arg));
                     }
                 } while(0);
                 break;
 
             case 'p':
                 if (proxypath) {
-                    usage();
+                    usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
                 }
                 proxypath = apr_pstrdup(pool, arg);
-                if (apr_filepath_set(proxypath, pool) != APR_SUCCESS) {
-                    usage();
+                if ((status = apr_filepath_set(proxypath, pool)) != APR_SUCCESS) {
+                    usage(apr_psprintf(pool, "Could not set filepath to '%s': %s",
+                               proxypath, apr_strerror(status, errmsg, sizeof errmsg)));
                 }
                 break;
             } /* switch */
         } /* else */
     } /* while */
 
+    if (argc <= 1) {
+       usage(NULL);
+    }
+
     if (o->ind != argc) {
-         usage();
+         usage("Additional parameters specified on the command line, aborting");
     }
 
-    if (isdaemon && (repeat <= 0 || verbose || realclean || dryrun)) {
-         usage();
+    if (isdaemon && repeat <= 0) {
+         usage("Option -d must be greater than zero");
+    }
+
+    if (isdaemon && (verbose || realclean || dryrun)) {
+         usage("Option -d cannot be used with -v, -r or -D");
     }
 
     if (!isdaemon && intelligent) {
-         usage();
+         usage("Option -i cannot be used without -d");
+    }
+
+    if (!proxypath) {
+         usage("Option -p must be specified");
     }
 
-    if (!proxypath || max <= 0) {
-         usage();
+    if (max <= 0) {
+         usage("Option -l must be greater than zero");
     }
 
     if (apr_filepath_get(&path, 0, pool) != APR_SUCCESS) {
-        usage();
+        usage(apr_psprintf(pool, "Could not get the filepath: %s",
+                       apr_strerror(status, errmsg, sizeof errmsg)));
     }
     baselen = strlen(path);