]> granicus.if.org Git - apache/commitdiff
use a smarter way to specify the limit
authorAndré Malo <nd@apache.org>
Sat, 6 Nov 2004 22:41:54 +0000 (22:41 +0000)
committerAndré Malo <nd@apache.org>
Sat, 6 Nov 2004 22:41:54 +0000 (22:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@105710 13f79535-47bb-0310-9956-ffa450edef68

support/htcacheclean.c

index 4e4e946a3fbfbe4d9c6867af304ce7357c9852d0..fd5e3ab83360bd24361eace01bbfd75b9cd4cb49 100644 (file)
@@ -692,32 +692,36 @@ static void usage(void)
     apr_file_printf(errfile,
     "%s -- program for cleaning the disk cache."                             NL
     "Usage: %s [-Dvrn] -pPATH -lLIMIT"                                       NL
-    "       %s [-Dvrn] -pPATH -LLIMIT"                                       NL
     "       %s [-ni] -dINTERVAL -pPATH -lLIMIT"                              NL
-    "       %s [-ni] -dINTERVAL -pPATH -LLIMIT"                              NL
+                                                                             NL
     "Options:"                                                               NL
     "  -d   Daemonize and repeat cache cleaning every INTERVAL minutes."     NL
     "       This option is mutually exclusive with the -D, -v and -r"        NL
     "       options."                                                        NL
+                                                                             NL
     "  -D   Do a dry run and don't delete anything. This option is mutually" NL
     "       exclusive with the -d option."                                   NL
+                                                                             NL
     "  -v   Be verbose and print statistics. This option is mutually"        NL
     "       exclusive with the -d option."                                   NL
+                                                                             NL
     "  -r   Clean thoroughly. This assumes that the Apache web server is "   NL
     "       not running. This option is mutually exclusive with the -d"      NL
     "       option."                                                         NL
+                                                                             NL
     "  -n   Be nice. This causes slower processing in favour of other"       NL
     "       processes."                                                      NL
+                                                                             NL
     "  -p   Specify PATH as the root directory of the disk cache."           NL
-    "  -l   Specify LIMIT as the total disk cache size limit in KBytes."     NL
-    "  -L   Specify LIMIT as the total disk cache size limit in MBytes."     NL
+                                                                             NL
+    "  -l   Specify LIMIT as the total disk cache size limit. Attach 'K'"    NL
+    "       or 'M' to the number for specifying KBytes or MBytes."           NL
+                                                                             NL
     "  -i   Be intelligent and run only when there was a modification of"    NL
     "       the disk cache. This option is only possible together with the"  NL
     "       -d option."                                                      NL,
     shortname,
     shortname,
-    shortname,
-    shortname,
     shortname
     );
 
@@ -833,17 +837,30 @@ int main(int argc, const char * const argv[])
                     usage();
                 }
                 limit_found = 1;
-                max = apr_atoi64(arg);
-                max *= KBYTE;
-                break;
 
-            case 'L':
-                if (limit_found) {
-                    usage();
-                }
-                limit_found = 1;
-                max = apr_atoi64(arg);
-                max *= MBYTE;
+                do {
+                    apr_status_t rv;
+                    char *end;
+
+                    rv = apr_strtoff(&max, arg, &end, 10);
+                    if (rv == APR_SUCCESS) {
+                        if ((*end == 'K' || *end == 'k') && !end[1]) {
+                            max *= KBYTE;
+                        }
+                        else if ((*end == 'M' || *end == 'm') && !end[1]) {
+                            max *= MBYTE;
+                        }
+                        else if (*end &&        /* neither empty nor [Bb] */
+                                 ((*end != 'B' && *end != 'b') || end[1])) {
+                            rv = APR_EGENERAL;
+                        }
+                    }
+                    if (rv != APR_SUCCESS) {
+                        apr_file_printf(errfile, "Invalid limit: %s"
+                                                 APR_EOL_STR APR_EOL_STR, arg);
+                        usage();
+                    }
+                } while(0);
                 break;
 
             case 'p':