From 1a647a2723b78dda499a4bb64443878562534d1e Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Tue, 16 Feb 2010 21:42:03 +0000 Subject: [PATCH] support/htcacheclean: Teach it how to write a pid file (modelled on httpd's writing of a pid file) so that it becomes possible to run more than one instance of htcacheclean on the same machine. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@910705 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 5 ++++ docs/manual/programs/htcacheclean.xml | 5 ++++ support/htcacheclean.c | 35 ++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 93d9eaf7be..a0b86985ae 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,11 @@ Changes with Apache 2.3.7 + *) support/htcacheclean: Teach it how to write a pid file (modelled on + httpd's writing of a pid file) so that it becomes possible to run + more than one instance of htcacheclean on the same machine. + [Graham Leggett] + *) Log command line on startup, so there's a record of command line arguments like -f. PR 48752. [Dan Poirier] diff --git a/docs/manual/programs/htcacheclean.xml b/docs/manual/programs/htcacheclean.xml index cb3a9b4340..973f48ce75 100644 --- a/docs/manual/programs/htcacheclean.xml +++ b/docs/manual/programs/htcacheclean.xml @@ -49,6 +49,7 @@ [ -n ] [ -t ] [ -i ] + [ -Ppidfile ] -dinterval -ppath -llimit

@@ -95,6 +96,10 @@ should be the same value as specified with the CacheRoot directive. +
-Ppidfile
+
Specify pidfile as the name of the file to write the + process ID to when daemonized.
+
-llimit
Specify limit as the total disk cache size limit. The value is expressed in bytes by default (or attaching B to the diff --git a/support/htcacheclean.c b/support/htcacheclean.c index 9991a9a496..b03c4710ab 100644 --- a/support/htcacheclean.c +++ b/support/htcacheclean.c @@ -708,8 +708,8 @@ static void usage(const char *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 + "Usage: %s [-Dvtrn] -pPATH -lLIMIT [-PPIDFILE]" NL + " %s [-nti] -dINTERVAL -pPATH -lLIMIT [-PPIDFILE]" NL NL "Options:" NL " -d Daemonize and repeat cache cleaning every INTERVAL minutes." NL @@ -735,6 +735,8 @@ static void usage(const char *error) NL " -p Specify PATH as the root directory of the disk cache." NL NL + " -P Specify PIDFILE as the file to write the pid file to." 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 @@ -770,7 +772,7 @@ int main(int argc, const char * const argv[]) int retries, isdaemon, limit_found, intelligent, dowork; char opt; const char *arg; - char *proxypath, *path; + char *proxypath, *path, *pidfile; char errmsg[1024]; interrupted = 0; @@ -786,6 +788,7 @@ int main(int argc, const char * const argv[]) intelligent = 0; previous = 0; /* avoid compiler warning */ proxypath = NULL; + pidfile = NULL; if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) { return 1; @@ -807,7 +810,7 @@ int main(int argc, const char * const argv[]) apr_getopt_init(&o, pool, argc, argv); while (1) { - status = apr_getopt(o, "iDnvrtd:l:L:p:", &opt, &arg); + status = apr_getopt(o, "iDnvrtd:l:L:p:P:", &opt, &arg); if (status == APR_EOF) { break; } @@ -912,6 +915,14 @@ int main(int argc, const char * const argv[]) proxypath, apr_strerror(status, errmsg, sizeof errmsg))); } break; + + case 'P': + if (pidfile) { + usage_repeated_arg(pool, opt); + } + pidfile = apr_pstrdup(pool, arg); + break; + } /* switch */ } /* else */ } /* while */ @@ -957,6 +968,22 @@ int main(int argc, const char * const argv[]) } #endif + if (pidfile) { + apr_file_t *file; + pid_t mypid = getpid(); + if (APR_SUCCESS == (status = apr_file_open(&file, pidfile, APR_WRITE + | APR_CREATE | APR_TRUNCATE, + APR_UREAD | APR_UWRITE | APR_GREAD, pool))) { + apr_file_printf(file, "%ld" APR_EOL_STR, (long) mypid); + apr_file_close(file); + } + else if (!isdaemon) { + apr_file_printf(errfile, + "Could not write the pid file '%s': %s" APR_EOL_STR, + pidfile, apr_strerror(status, errmsg, sizeof errmsg)); + } + } + do { apr_pool_create(&instance, pool); -- 2.40.0