Summary: | pid file may get corrupted and prevent httpd from starting | ||
---|---|---|---|
Product: | Apache httpd-2 | Reporter: | Nicolas Carrier <carrier.nicolas0> |
Component: | Core | Assignee: | Apache HTTPD Bugs Mailing List <bugs> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | carrier.nicolas0 |
Priority: | P2 | Keywords: | PatchAvailable |
Version: | 2.5-HEAD | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Linux | ||
Attachments: | Avoids pid file creation race condition by using a temporary file. |
Description
Nicolas Carrier
2019-02-04 10:59:23 UTC
Created attachment 36417 [details]
Avoids pid file creation race condition by using a temporary file.
The original pattern for creating the pid file was:
open_create(pid_file)
write(pid_file, pid)
close(pid_file)
But if a power outage occurs between open_create and write, the file will
be empty and httpd will refuse to start afterwards unless the corrupt pid
file is removed.
This patch uses the pattern:
open_create(temp_pid_file)
write(temp_pid_file)
close(temp_pid_file)
rename(temp_pid_file, pid_file)
which is guaranteed to be atomic, provided that temp_pid_file and pid_file
are located in the same file system, which this patch does by creating
a temporary file name with the pattern:
pid_file_name + random_suffix
There has been no progress with this issue for more than 3 month. Is this issue invalid somehow? Is the patch not acceptable? The pid file is not created in a temporary directory but in the current directory. If the directory in which the pid file will be created is on a different filesystem than the current directory the rename call will fail. [Sat Feb 22 00:01:33.948798 2020] [core:error] [pid 38525:tid 139718597842752] (18)Invalid cross-device link: AH00102: could not rename file httpd.pid.rK6Vaj to /usr/local/apache2/logs/httpd.pid I extended Nicolas' patch here https://github.com/apache/httpd/pull/100/commits/b5eb2611ea209147476868c8a09e288a132b8a13 to create the temp file in the same directory as the pidfile and add error checking, will merge if Travis is happy. |