bgsave: ensure kit processes die when their parents do.

Potentially zombie / badly behaving kits should be taken down
by the kernel, and this lets us continue our cleanup by killing
just the parent process.

Change-Id: I1e81f41cded0c67b72622f8ed88602daf427238c
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
pull/8693/head
Michael Meeks 2024-04-15 09:52:12 +01:00 committed by Caolán McNamara
parent 85fc0fd841
commit a8102212c6
3 changed files with 16 additions and 0 deletions

View File

@ -24,6 +24,10 @@
#include <sys/uio.h>
#include <unistd.h>
#if !defined(ANDROID) && !defined(IOS)
# include <sys/prctl.h>
#endif
#include <atomic>
#include <cassert>
#include <chrono>
@ -546,6 +550,13 @@ void requestShutdown()
}
void dieOnParentDeath()
{
#if !defined(ANDROID) && !defined(IOS)
prctl(PR_SET_PDEATHSIG, SIGKILL);
#endif
}
static
void handleUserSignal(const int signal)
{

View File

@ -126,6 +126,9 @@ namespace SigUtil
/// Sets a child death signal handler
void setSigChildHandler(SigChildHandler fn);
/// Ensure that if a parent process is killed we go down too
void dieOnParentDeath();
/// Dump a signal-safe back-trace
void dumpBacktrace();

View File

@ -1420,6 +1420,8 @@ bool Document::forkToSave(const std::function<void()> &childSave, int viewId)
SigUtil::addActivity("forked background save process: " +
std::to_string(pid));
SigUtil::dieOnParentDeath();
childSocket.reset();
// now we just have a single socket to our parent