Not handle system shutdown (SIGTERM)
Categories
(Core :: Widget: Gtk, defect, P2)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox122 | --- | fixed |
People
(Reporter: vip4444, Assigned: stransky)
References
Details
Attachments
(2 files, 2 obsolete files)
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/116.0
Steps to reproduce:
I shutdown my system by /sbin/poweroff (/sbin/reboot) or by dbus command "dbus-send --system --print-reply --dest=org.freedesktop.login1 /org/freedesktop/login1 "org.freedesktop.login1.Manager.PowerOff" boolean:true", but after next run system FireFox starting as after crash, not as after correct shutdown. If I close FF by "Close" button on program caption or by command "File->Exit" in menu - all Ok.
Actual results:
Not handle system shutdown.
Expected results:
Handle system shutdown.
Comment 1•2 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Printing: Output' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Also bug occur when "killall firefox" and not occur when close by "wmctrl -c 'Firefox'".
Comment 3•2 years ago
|
||
The severity field is not set for this bug.
:emilio, could you have a look please?
For more information, please visit BugBot documentation.
Comment 4•2 years ago
|
||
Well you're killing Firefox, maybe we could do something more graceful for SIGTERM or use some sort of shutdown blocker and wait for clean shutdown? But not sure how much of a rabbit-hole that would be.
| Assignee | ||
Updated•2 years ago
|
Comment 5•2 years ago
|
||
Based on comment 4 change status to "New".
| Assignee | ||
Comment 6•2 years ago
|
||
Yes, it's possible to do that. We'd need to add another handler here:
https://searchfox.org/mozilla-central/rev/d81e60336d9f498ad3985491dc17c2b77969ade4/widget/gtk/nsAppShell.cpp#216
We may copy what Windows does:
https://searchfox.org/mozilla-central/rev/d81e60336d9f498ad3985491dc17c2b77969ade4/widget/windows/nsWindow.cpp#4936
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Comment 7•2 years ago
|
||
Alexander, do you mind to try to create a patch for it? a mini-howto can be found here:
https://mastransky.wordpress.com/2023/07/04/no-one-fights-alone-a-guide-to-your-first-firefox-patch-on-linux/
Thanks.
I do not have ready solution for make patch.
This is requiring research.
https://stackoverflow.com/questions/22009705/how-to-detect-linux-shutdown-reboot
Only signal handling is not enough to solve this problem.
I have handled signals in my program, but it work only for Ctrl+C situation, not for shutdown system.
https://github.com/galaxysite/gorg64_spkplay/blob/main/gorg64_spkplay.pas
May be this problem already resolved in Falkon ?
https://github.com/KDE/falkon
Outwardly it looks like this.
Also I do not have ready solution for dbus.
| Assignee | ||
Comment 9•2 years ago
|
||
You can handle the DBus message 'org.freedesktop.login1.Manager.PowerOff'. Not sure if it's even possible to catch /sbin/poweroff and if that sends any signal to application.
IIUC Windows try to catch SIGTERM here:
https://searchfox.org/mozilla-central/rev/d81e60336d9f498ad3985491dc17c2b77969ade4/widget/windows/nsWindow.cpp#4936
(or something which matches SIGTERM on Windows) so can the code be the same on Linux and may it be executed in SIGTERM handler?
| Assignee | ||
Comment 10•2 years ago
|
||
Looks like poweroff directly uses reboot kernel call (https://man7.org/linux/man-pages/man2/reboot.2.html) and it's kind of emergency shutdown. I doubt any desktop application/environment can handle this kind of shutdown seamlessly.
| Reporter | ||
Comment 11•2 years ago
|
||
Not-not, poweroff is not emergency. This is the standard, non-emergency way for shutdown of a System. poweroff/reboot - command for change runlevel of System: https://www.geeksforgeeks.org/run-levels-linux/ All other ways more modern: poweroff/reboot historical, standard way of shutdown.
| Reporter | ||
Comment 12•2 years ago
|
||
SIGTERM on Windows
Only process messages. Signals are not exactly messages.
In the old days, I solved this problem like this:
...
procedure OnQEnd(Var Msg : TMessage); message WM_QUERYENDSESSION;
procedure OnEnd(Var Msg : TMessage); message WM_ENDSESSION;
procedure OnSysCommand(Var Msg: TWMSysCommand); message WM_SYSCOMMAND;
...
procedure MyMain.OnSysCommand(Var Msg: TWMSysCommand);
begin
if msg.CmdType = SC_CLOSE then begin
if MessageBox(hwnd, PCHar(app_quit), PCHar(app_name), bit6 or bit3) <> ID_YES then begin msg.Result := 0; exit; end;
end;
msg.Result := DefWindowProc(hwnd, msg.msg, TMessage(msg).WParam, TMessage(msg).LParam);
end;
procedure MyMain.OnQEnd(Var Msg : TMessage);
begin
app.terminated := true;
msg.Result := Longint(true);
end;
procedure MyMain.OnEnd(Var Msg : TMessage);
begin
while app.terminated do sleep(0); // during the shutdown of the program and saving its files in 2-st thread
msg.Result := 0;
end;
| Reporter | ||
Comment 13•2 years ago
|
||
May be solution is here ? : https://chromium.googlesource.com/chromium/src/+/78.0.3904.108/chrome/app/shutdown_signal_handlers_posix.cc
| Reporter | ||
Comment 14•2 years ago
|
||
I quest about this systemd creators and get answer:
https://github.com/systemd/systemd/issues/29146
We emit PrepareForShutdown dbus signal before/after initiating the shutdown process: https://www.freedesktop.org/software/systemd/man/org.freedesktop.login1.html#Signals
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Updated•2 years ago
|
| Assignee | ||
Comment 15•2 years ago
|
||
We want to handle SIGTERM gracefully and terminate Firefox by standard way.
Updated•2 years ago
|
| Assignee | ||
Comment 16•2 years ago
|
||
SIGTERM is supposed to be a standard way how to terminate Linux application. So don't fire emergency exit but run usual exit sequence.
Depends on D191077
Comment 17•2 years ago
|
||
Comment 18•2 years ago
•
|
||
Backed out for causing xpcshell failures in marSuccessPartialWhileBackgroundTaskRunning.js.
- Backout link
- Push with failures
- Failure Log
- Failure line: TEST-UNEXPECTED-FAIL | toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartialWhileBackgroundTaskRunning.js | xpcshell return code: 0
L.E. There are also these Mn failures.
| Assignee | ||
Comment 19•2 years ago
|
||
Install SIGTERM handler only if we use event loop. That keeps default SIGTERM handler for applications without event loop like xpcshell.
Depends on D191079
| Assignee | ||
Updated•2 years ago
|
Comment 20•2 years ago
|
||
Comment 21•2 years ago
|
||
Backed out for causing xpc failures on toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartialWhileBackgroundTaskRunning.js
Backout link: https://hg.mozilla.org/integration/autoland/rev/e7f56b0ae07ad09c48bb7db75fcbbb2e320fe483
| Assignee | ||
Comment 22•2 years ago
|
||
Surprisingly event loop is also called on xpcshell but when it's terminated. So we need to use something different here.
Updated•2 years ago
|
| Assignee | ||
Comment 23•2 years ago
|
||
Depends on D191079
| Assignee | ||
Updated•2 years ago
|
Comment 24•2 years ago
|
||
Comment 25•2 years ago
•
|
||
Backed for causing marionette crashes.
Failure log: https://treeherder.mozilla.org/logviewer?job_id=437036027&repo=autoland
Backout link: https://hg.mozilla.org/integration/autoland/rev/9eb2cb31618c369f011b1799ed328122558aa9a4
LE: also these Gtest failures: https://treeherder.mozilla.org/logviewer?job_id=437056477&repo=autoland
Updated•2 years ago
|
Updated•2 years ago
|
Comment 26•2 years ago
|
||
Comment 27•2 years ago
•
|
||
Backed out for causing xpcshell failures in marSuccessPartialWhileBackgroundTaskRunning.js
- Backout link
- Push with failures
- Failure Log
- Failure line: TEST-UNEXPECTED-FAIL | toolkit/mozapps/update/tests/unit_base_updater/marSuccessPartialWhileBackgroundTaskRunning.js | run_test - [run_test : 115] -15 == -9
And also marionette failures: https://treeherder.mozilla.org/jobs?repo=autoland&group_state=expanded&searchStr=linux%2C18.04%2Cx64%2Cwebrender%2Cdebug%2Ctest-linux1804-64-qr%2Fdebug-marionette-swr%2Cmn-swr&revision=1035a42c6a86393419461fd90d38c7fa183b92f3&selectedTaskRun=YB-XIBOKS9-5VDMu3MCKzA.0
| Assignee | ||
Comment 28•2 years ago
|
||
Comment 29•2 years ago
|
||
| Assignee | ||
Updated•2 years ago
|
Comment 30•2 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/7fe397f45f7b
https://hg.mozilla.org/mozilla-central/rev/f5150abdafbd
Description
•