Cleanup ForKit's SocketPoll after forking.

Don't leave the wake-pipes lying around; it can't do any good
to have these cloned, and shared between child processes.

Change-Id: Ieb6c5c8fdd1285bc514116a1e00de76bcc5a1773
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
This commit is contained in:
Michael Meeks 2024-03-12 20:09:40 +00:00 committed by Caolán McNamara
parent e9ef062eee
commit d6c49d4183

View file

@ -70,6 +70,9 @@ static std::map<pid_t, std::string> childJails;
/// The jails that need cleaning up. This should be small.
static std::vector<std::string> cleanupJailPaths;
/// The Main polling main-loop of this (single threaded) process
static std::unique_ptr<SocketPoll> ForKitPoll;
extern "C" { void dump_forkit_state(void); /* easy for gdb */ }
void dump_forkit_state()
@ -428,6 +431,11 @@ static int createLibreOfficeKit(const std::string& childRoot,
// Close the pipe from coolwsd
close(0);
// Close the ForKit main-loop's sockets
if (ForKitPoll)
ForKitPoll->closeAllSockets();
// else very first kit process spawned
UnitKit::get().postFork();
sleepForDebugger();
@ -773,13 +781,13 @@ int forkit_main(int argc, char** argv)
Log::logger().setLevel(LogLevel);
}
SocketPoll mainPoll(Util::getThreadName());
mainPoll.runOnClientThread(); // We will do the polling on this thread.
ForKitPoll.reset(new SocketPoll (Util::getThreadName()));
ForKitPoll->runOnClientThread(); // We will do the polling on this thread.
WSHandler = std::make_shared<ServerWSHandler>("forkit_ws");
#if !MOBILEAPP
if (!mainPoll.insertNewUnixSocket(MasterLocation, FORKIT_URI, WSHandler))
if (!ForKitPoll->insertNewUnixSocket(MasterLocation, FORKIT_URI, WSHandler))
{
LOG_SFL("Failed to connect to WSD. Will exit.");
Util::forcedExit(EX_SOFTWARE);
@ -795,7 +803,7 @@ int forkit_main(int argc, char** argv)
{
UnitKit::get().invokeForKitTest();
mainPoll.poll(std::chrono::microseconds(POLL_TIMEOUT_MICRO_S));
ForKitPoll->poll(std::chrono::microseconds(POLL_TIMEOUT_MICRO_S));
SigUtil::checkDumpGlobalState(dump_forkit_state);