From 3d36df0160136c1b0dc7dff5f76e236de9aa890f Mon Sep 17 00:00:00 2001 From: Eric Covener Date: Sat, 19 Sep 2009 12:28:58 +0000 Subject: [PATCH] Merge r814091, r814779, r81544, r816701 from trunk: htcacheclean: 19 ways to fail, 1 error message. Fixed. Move declaration to remove a compiler warning. Detab. Submitted by: minfrin, trawick Reviewed by: minfrin, poirier, covener git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@816906 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 2 ++ STATUS | 7 ----- support/htcacheclean.c | 65 ++++++++++++++++++++++++++---------------- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/CHANGES b/CHANGES index e6c48eae882..b178f02fe1a 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,8 @@ Changes with Apache 2.2.14 mod_proxy_ftp: NULL pointer dereference on error paths. [Stefan Fritsch , Joe Orton] + *) htcacheclean: 19 ways to fail, 1 error message. Fixed. [Graham Leggett] + *) mod_ldap: Bring the LDAPCacheEntries and LDAPOpCacheEntries usage() in synch with the manual and the implementation (0 and -1 both disable the cache). [Eric Covener] diff --git a/STATUS b/STATUS index bcad22dc09b..e2c23a1c4ca 100644 --- a/STATUS +++ b/STATUS @@ -89,13 +89,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * htcacheclean: 19 ways to fail, 1 error message. Fixed. - Trunk Patch: http://svn.apache.org/viewvc?view=rev&revision=814091 - http://svn.apache.org/viewvc?view=rev&revision=814779 - http://svn.apache.org/viewvc?rev=815448&view=rev - http://svn.apache.org/viewvc?view=rev&revision=816701 - +1: minfrin, poirier, covener - PATCHES PROPOSED TO BACKPORT FROM TRUNK: [ New proposals should be added at the end of the list ] diff --git a/support/htcacheclean.c b/support/htcacheclean.c index 36a80051f09..e826639a118 100644 --- a/support/htcacheclean.c +++ b/support/htcacheclean.c @@ -697,9 +697,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 @@ -758,6 +761,7 @@ int main(int argc, const char * const argv[]) char opt; const char *arg; char *proxypath, *path; + char errmsg[1024]; interrupted = 0; repeat = 0; @@ -798,48 +802,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; @@ -847,7 +851,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); @@ -857,7 +861,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; @@ -882,44 +886,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); -- 2.47.2