PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
[ start all new proposals below, under PATCHES PROPOSED. ]
- * 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.
- Trunk patch: http://svn.apache.org/viewvc?rev=910705&view=rev
- http://svn.apache.org/viewvc?rev=910735&view=rev
- http://svn.apache.org/viewvc?rev=910756&view=rev
- http://svn.apache.org/viewvc?rev=917002&view=rev
- http://svn.apache.org/viewvc?rev=917005&view=rev
- 2.2.x patch: http://people.apache.org/~minfrin/htcacheclean-pid.patch
- +1: minfrin, sf, trawick, jim
-
* Introduce SSLFIPS directive to support OpenSSL FIPS_mode; permits all
builds of mod_ssl to use 'SSLFIPS off' for portability, but the proper
build of openssl is required for 'SSLFIPS on'.
}
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
NL
" -p Specify PATH as the root directory of the disk cache." NL
NL
+ " -P Specify PIDFILE as the file to write the pid 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
}
#undef NL
+static void log_pid(apr_pool_t *pool, const char *pidfilename, apr_file_t **pidfile)
+{
+ apr_status_t status;
+ char errmsg[120];
+ pid_t mypid = getpid();
+
+ if (APR_SUCCESS == (status = apr_file_open(pidfile, pidfilename,
+ APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE |
+ APR_FOPEN_DELONCLOSE, APR_FPROT_UREAD | APR_FPROT_UWRITE |
+ APR_FPROT_GREAD | APR_FPROT_WREAD, pool))) {
+ apr_file_printf(*pidfile, "%" APR_PID_T_FMT APR_EOL_STR, mypid);
+ }
+ else {
+ if (errfile) {
+ apr_file_printf(errfile,
+ "Could not write the pid file '%s': %s" APR_EOL_STR,
+ pidfilename,
+ apr_strerror(status, errmsg, sizeof errmsg));
+ }
+ exit(1);
+ }
+}
+
/*
* main
*/
apr_pool_t *pool, *instance;
apr_getopt_t *o;
apr_finfo_t info;
+ apr_file_t *pidfile;
int retries, isdaemon, limit_found, intelligent, dowork;
char opt;
const char *arg;
- char *proxypath, *path;
+ char *proxypath, *path, *pidfilename;
char errmsg[1024];
interrupted = 0;
intelligent = 0;
previous = 0; /* avoid compiler warning */
proxypath = NULL;
+ pidfilename = NULL;
if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
return 1;
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;
}
proxypath, apr_strerror(status, errmsg, sizeof errmsg)));
}
break;
+
+ case 'P':
+ if (pidfilename) {
+ usage(apr_psprintf(pool, "The option '%c' cannot be specified more than once", (int)opt));
+ }
+ pidfilename = apr_pstrdup(pool, arg);
+ break;
+
} /* switch */
} /* else */
} /* while */
}
baselen = strlen(path);
+ if (pidfilename) {
+ log_pid(pool, pidfilename, &pidfile); /* before daemonizing, so we
+ * can report errors
+ */
+ }
+
#ifndef DEBUG
if (isdaemon) {
apr_file_close(errfile);
+ errfile = NULL;
+ if (pidfilename) {
+ apr_file_close(pidfile); /* delete original pidfile only in parent */
+ }
apr_proc_detach(APR_PROC_DETACH_DAEMONIZE);
+ if (pidfilename) {
+ log_pid(pool, pidfilename, &pidfile);
+ }
}
#endif