Skip to content

Commit

Permalink
kill saving thread with SIGABRT
Browse files Browse the repository at this point in the history
so the the correct/main thread gets the signal so we can get a backtrace
generated.

Signed-off-by: Caolán McNamara <[email protected]>
Change-Id: I64f8f374bad92964f42ba34e23011bf827d87bf9
  • Loading branch information
caolanm committed Jan 10, 2025
1 parent 86203fc commit af37080
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ static LokHookFunction2* initFunction = nullptr;
class BackgroundSaveWatchdog
{
public:
BackgroundSaveWatchdog(unsigned mobileAppDocId)
BackgroundSaveWatchdog(unsigned mobileAppDocId, pid_t savingTid)
: _saveCompleted(false)
, _watchdogThread(
// mobileAppDocId is on the stack, so capture it by value.
[mobileAppDocId, this]()
[mobileAppDocId, savingTid, this]()
{
Util::setThreadName("kitbgsv_" + Util::encodeId(mobileAppDocId, 3) + "_wdg");

Expand All @@ -201,7 +201,7 @@ class BackgroundSaveWatchdog
LOG_WRN("BgSave timed out and will self-destroy");
Log::shutdown(); // Flush logs.
// raise(3) will exit the current thread, not the process.
::kill(0, SIGKILL); // kill(2) is trapped by seccomp.
Util::killThreadById(savingTid, SIGABRT);
}
})
{
Expand Down Expand Up @@ -1487,7 +1487,7 @@ bool Document::forkToSave(const std::function<void()> &childSave, int viewId)
Util::sleepFromEnvIfSet("KitBackgroundSave", "SLEEPBACKGROUNDFORDEBUGGER");

assert(!BgSaveWatchdog && "Unexpected to have BackgroundSaveWatchdog instance");
BgSaveWatchdog = std::make_unique<BackgroundSaveWatchdog>(_mobileAppDocId);
BgSaveWatchdog = std::make_unique<BackgroundSaveWatchdog>(_mobileAppDocId, gettid());

UnitKit::get().postBackgroundSaveFork();

Expand Down

0 comments on commit af37080

Please sign in to comment.