From b0a00784da9400e0a5a1fc164845ceac33e36b80 Mon Sep 17 00:00:00 2001 From: "Meir Shpilraien (Spielrein)" Date: Tue, 22 Dec 2020 15:17:39 +0200 Subject: [PATCH] Fix issue where fork process deletes the parent pidfile (#8231) Turns out that when the fork child crashes, the crash log was deleting the pidfile from the disk (although the parent is still running. Now we set the pidfile of the fork process to NULL so the fork process will never deletes it. (cherry picked from commit 4192faa9821aa4c19be3bd245d8366a1bc1b0332) --- src/debug.c | 2 +- src/server.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/debug.c b/src/debug.c index 389b4e36f..a5786edc0 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1724,7 +1724,7 @@ void sigsegvHandler(int sig, siginfo_t *info, void *secret) { ); /* free(messages); Don't call free() with possibly corrupted memory. */ - if (server.daemonize && server.supervised == 0) unlink(server.pidfile); + if (server.daemonize && server.supervised == 0 && server.pidfile) unlink(server.pidfile); /* Make sure we exit with the right signal at the end. So for instance * the core will be dumped if enabled. */ diff --git a/src/server.c b/src/server.c index 51beeecbd..5f5333ce4 100644 --- a/src/server.c +++ b/src/server.c @@ -5085,6 +5085,10 @@ void closeClildUnusedResourceAfterFork() { closeListeningSockets(0); if (server.cluster_enabled && server.cluster_config_file_lock_fd != -1) close(server.cluster_config_file_lock_fd); /* don't care if this fails */ + + /* Clear server.pidfile, this is the parent pidfile which should not + * be touched (or deleted) by the child (on exit / crash) */ + server.pidfile = NULL; } /* purpose is one of CHILD_TYPE_ types */