diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2022-06-13 22:17:40 -0400 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2022-07-12 13:43:43 +0100 |
commit | b0d6e1b8599a861af4aa1de1aa3620a956ae1b56 (patch) | |
tree | 515f6d1747cd124ce4ad864376f91643f796a607 /wsd | |
parent | wsd: sig: dump backtrace with USR2 (diff) | |
download | online-b0d6e1b8599a861af4aa1de1aa3620a956ae1b56.tar.gz online-b0d6e1b8599a861af4aa1de1aa3620a956ae1b56.zip |
wsd: sig: forward USR2 to child processes
We now have USR2 signal that dumps the
stack-trace of each process. This is useful for
capturing the state of misbehaving instances.
COOLWSD forwards USR2 to forkit and the kits
so they dump their stacktraces too.
This patch does not change the behavior of USR1.
Specifically, unlike USR2, USR1 is not forwarded
from wsd to frk and the kits. Also unlike USR2,
USR1 dumps into stderr.
Change-Id: I1d82f678f30f430f627692cc42961b1928f69e11
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Diffstat (limited to 'wsd')
-rw-r--r-- | wsd/COOLWSD.cpp | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/wsd/COOLWSD.cpp b/wsd/COOLWSD.cpp index 1dc3d92b9c..da9936e64d 100644 --- a/wsd/COOLWSD.cpp +++ b/wsd/COOLWSD.cpp @@ -213,7 +213,11 @@ static std::map<std::string, std::shared_ptr<DocumentBroker> > DocBrokers; static std::mutex DocBrokersMutex; static Poco::AutoPtr<Poco::Util::XMLConfiguration> KitXmlConfig; -extern "C" { void dump_state(void); /* easy for gdb */ } +extern "C" +{ + void dump_state(void); /* easy for gdb */ + void forwardSigUsr2(); +} #if ENABLE_DEBUG static std::chrono::milliseconds careerSpanMs(std::chrono::milliseconds::zero()); @@ -367,7 +371,6 @@ void COOLWSD::checkDiskSpaceAndWarnClients(const bool cacheLastCheck) /// Remove dead and idle DocBrokers. /// The client of idle document should've greyed-out long ago. -/// Returns true if at least one is removed. void cleanupDocBrokers() { Util::assertIsLocked(DocBrokersMutex); @@ -2838,7 +2841,10 @@ void PrisonPoll::wakeupHook() #endif std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex, std::defer_lock); if (docBrokersLock.try_lock()) + { cleanupDocBrokers(); + SigUtil::checkForwardSigUsr2(forwardSigUsr2); + } } #if !MOBILEAPP @@ -5487,6 +5493,43 @@ void dump_state() LOG_TRC(msg); } +void forwardSigUsr2() +{ + LOG_TRC("forwardSigUsr2"); + + Util::assertIsLocked(DocBrokersMutex); + std::lock_guard<std::mutex> newChildLock(NewChildrenMutex); + +#if !MOBILEAPP +#ifndef KIT_IN_PROCESS + if (COOLWSD::ForKitProcId > 0) + { + LOG_INF("Sending SIGUSR2 to forkit " << COOLWSD::ForKitProcId); + ::kill(COOLWSD::ForKitProcId, SIGUSR2); + } +#endif +#endif + + for (const auto& child : NewChildren) + { + if (child && child->getPid() > 0) + { + LOG_INF("Sending SIGUSR2 to child " << child->getPid()); + ::kill(child->getPid(), SIGUSR2); + } + } + + for (const auto& pair : DocBrokers) + { + std::shared_ptr<DocumentBroker> docBroker = pair.second; + if (docBroker) + { + LOG_INF("Sending SIGUSR2 to docBroker " << docBroker->getPid()); + ::kill(docBroker->getPid(), SIGUSR2); + } + } +} + // Avoid this in the Util::isFuzzing() case because libfuzzer defines its own main(). #if !MOBILEAPP && !LIBFUZZER |