Skip to content

Commit

Permalink
Bug 1837907 [Linux] Enable AppShell SIGTERM signal handler for Firefo…
Browse files Browse the repository at this point in the history
…x r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D194183
  • Loading branch information
stransky committed Nov 29, 2023
1 parent ca66547 commit ff8cc58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions browser/app/nsBrowserApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ int main(int argc, char* argv[], char* envp[]) {
mozilla::CreateAndStorePreXULSkeletonUI(GetModuleHandle(nullptr), argc, argv);
#endif

#if defined(XP_UNIX)
setenv("MOZ_ENABLE_APPSHELL_SIG_HANDLER", "1", true);
#endif

nsresult rv = InitXPCOMGlue(LibLoadingStrategy::ReadAhead);
if (NS_FAILED(rv)) {
return 255;
Expand Down
23 changes: 15 additions & 8 deletions widget/gtk/nsAppShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ void nsAppShell::TermSignalHandler(int signo) {
}

void nsAppShell::InstallTermSignalHandler() {
if (!PR_GetEnv("MOZ_ENABLE_APPSHELL_SIG_HANDLER")) {
return;
}
unsetenv("MOZ_ENABLE_APPSHELL_SIG_HANDLER");

if (!XRE_IsParentProcess() || PR_GetEnv("MOZ_DISABLE_SIG_HANDLER")) {
return;
}

struct sigaction act = {}, oldact;
act.sa_handler = TermSignalHandler;
sigfillset(&act.sa_mask);
Expand Down Expand Up @@ -446,9 +455,7 @@ nsresult nsAppShell::Init() {
mTag = g_source_attach(source, nullptr);
g_source_unref(source);

if (XRE_IsParentProcess() && !PR_GetEnv("MOZ_DISABLE_SIG_HANDLER")) {
InstallTermSignalHandler();
}
InstallTermSignalHandler();

return nsBaseAppShell::Init();
failed:
Expand Down Expand Up @@ -476,15 +483,15 @@ void nsAppShell::ScheduleNativeEventCallback() {
Unused << write(mPipeFDs[1], buf, 1);
}

void nsAppShell::ScheduleQuitEvent() {
unsigned char buf[] = {QUIT_TOKEN};
Unused << write(mPipeFDs[1], buf, 1);
}

bool nsAppShell::ProcessNextNativeEvent(bool mayWait) {
if (mSuspendNativeCount) {
return false;
}
bool didProcessEvent = g_main_context_iteration(nullptr, mayWait);
return didProcessEvent;
}

void nsAppShell::ScheduleQuitEvent() {
unsigned char buf[] = {QUIT_TOKEN};
Unused << write(mPipeFDs[1], buf, 1);
}

0 comments on commit ff8cc58

Please sign in to comment.