package/apache: atomic creation of pid file.
authorNicolas Carrier <nicolas.carrier@orolia.com>
Mon, 23 Sep 2019 07:47:27 +0000 (07:47 +0000)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Mon, 13 Apr 2020 09:06:09 +0000 (11:06 +0200)
commit67fbb903b60ad4832431d6c47161e312144365a0
treec889e4547c9d46e36caca77144bea1e83fca0c57
parent5234acc639034c3fd3ab76908fd06471f73129c6
package/apache: atomic creation of pid 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

Patch is upstream as of
https://github.com/apache/httpd/commit/dd10a9352e87a868ad527022bbafdc3b82cc6d0a,
which will be in the next 2.5.x version.

Signed-off-by: Nicolas Carrier <nicolas.carrier@orolia.com>
[Thomas: update to use upstreamed patch.]
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
package/apache/0004-server-log.c-ap_log_pid-Use-a-temporary-file-then-re.patch [new file with mode: 0644]