When, with httpd-2.1, the pid file exists but has a zero size, then httpd refuses to start.
The attached patch changes this behavior and removes the empty pid file (but only if it exists AND is empty) and logs a message: (17)File exists: Zero-length PID file logs/httpd.pid ignored. to the console during startup. Not a very frequent error indeed.... Martin -- <[EMAIL PROTECTED]> | Fujitsu Siemens Fon: +49-89-636-46021, FAX: +49-89-636-47655 | 81730 Munich, Germany
? server/core.c.off ? server/export_files.off ? server/mpm/mpmt_pthread/.deps ? server/mpm/mpmt_pthread/.libs ? server/mpm/mpmt_pthread/Makefile ? server/mpm/mpmt_pthread/libmpmt_pthread.la ? server/mpm/mpmt_pthread/mpmt_pthread.lo ? server/mpm/mpmt_pthread/scoreboard.lo Index: server/log.c =================================================================== RCS file: /home/cvs/httpd-2.0/server/log.c,v retrieving revision 1.140 diff -u -r1.140 log.c --- server/log.c 12 Jan 2004 22:48:08 -0000 1.140 +++ server/log.c 5 Feb 2004 12:31:32 -0000 @@ -696,6 +696,7 @@ const char *fname; char *buf, *endptr; apr_size_t bytes_read; + apr_finfo_t finfo; if (!filename) { return APR_EGENERAL; @@ -713,18 +714,31 @@ return rv; } + /* If there's a zero length pid file, unlink it */ + if (APR_SUCCESS == apr_file_info_get(&finfo, APR_FINFO_SIZE, pid_file) && + 0 == finfo.size) { + apr_file_close(pid_file); + if (APR_SUCCESS == apr_file_remove(fname, p)) + ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_ERR, APR_EEXIST, + NULL, "Zero-length PID file %s ignored.", filename); + return APR_ENOENT; + } + /* Ensure null-termination, so that strtol doesn't go crazy. */ buf = apr_palloc(p, BUFFER_SIZE); buf[BUFFER_SIZE - 1] = '\0'; rv = apr_file_read_full(pid_file, buf, BUFFER_SIZE - 1, &bytes_read); if (rv != APR_SUCCESS && rv != APR_EOF) { + apr_file_close(pid_file); return rv; } /* If we fill the buffer, we're probably reading a corrupt pid file. * To be nice, let's also ensure the first char is a digit. */ if (bytes_read == BUFFER_SIZE - 1 || !apr_isdigit(*buf)) { + apr_file_close(pid_file); + return APR_EGENERAL; }