}
}
- /* this may look strange but apr_stat() may return errno which
+ /* this may look strange but apr_stat() may return an error which
* is system dependent and there may be transient failures,
* so just blindly retry for a short while
*/
}
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
int retries, isdaemon, limit_found, intelligent, dowork;
char opt;
const char *arg;
- char *proxypath, *path;
+ char *proxypath, *path, *pidfile;
char errmsg[1024];
interrupted = 0;
intelligent = 0;
previous = 0; /* avoid compiler warning */
proxypath = NULL;
+ pidfile = 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_pstrdup(pool, arg);
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)));
+ 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 */
if (argc <= 1) {
- usage(NULL);
+ usage(NULL);
}
if (o->ind != argc) {
if (apr_filepath_get(&path, 0, pool) != APR_SUCCESS) {
usage(apr_psprintf(pool, "Could not get the filepath: %s",
- apr_strerror(status, errmsg, sizeof errmsg)));
+ apr_strerror(status, errmsg, sizeof errmsg)));
}
baselen = strlen(path);
}
#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_DELONCLOSE,
+ APR_UREAD | APR_UWRITE | APR_GREAD, pool))) {
+ apr_file_printf(file, "%" APR_PID_T_FMT APR_EOL_STR, mypid);
+ }
+ 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);