Bug 531634 - [GTK] Linux: send Close event on the display if receiving SIGTERM (on system shutdown)
Summary: [GTK] Linux: send Close event on the display if receiving SIGTERM (on system ...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 normal with 4 votes (vote)
Target Milestone: 4.12 M3   Edit
Assignee: Alexandr Miloslavskiy CLA
QA Contact: Eric Williams CLA
URL:
Whiteboard:
Keywords: noteworthy, triaged
Depends on:
Blocks:
 
Reported: 2018-02-24 09:17 EST by Thomas Singer CLA
Modified: 2019-06-30 10:23 EDT (History)
8 users (show)

See Also:


Attachments
Test snippet (1.24 KB, text/plain)
2019-04-17 16:17 EDT, Alexandr Miloslavskiy CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Singer CLA 2018-02-24 09:17:56 EST
On OS X the display's Close listener is invoked when shutting down the system. It would be nice if that also would occur for Linux.
Comment 1 Lars Vogel CLA 2018-02-26 04:26:39 EST
Nikita, are you interested in providing a patch for this one?
Comment 2 Leo Ufimtsev CLA 2018-02-26 10:08:39 EST
As a note, Nikita mentioned:

"GTK has g_unix_signal_add() that dispatches a callback to the GUI thread.
SWT could use it to send Close and dispose the display."
Comment 3 Nikita Nemkin CLA 2018-02-27 08:18:38 EST
I've looked into this and here's what I found:

 * SIGTERM only covers explicit termination via kill or Task Manager (aka System Monitor).
 * SIGHUP might also be used as a graceful termination signal.
 * GTK apps don't receive SIGHUP or SIGTERM during logout/shutdown (at least on GNOME).
 * The "proper" way to get logout/shutdown notifications is to register with the Session Manager.
 * There are two SM protocols currently in use: XSMP and GNOME SessionManager on D-Bus.
 * GTK2 has no direct SM support. There are two obsolete SM libraries: GnomeClient and EggSMClient.
 * GTK3 has direct support for D-Bus SessionManager in GtkApplication, but it doesn't signal QueryEndSession (where Display Close event should be sent from), isn't compatible with the SWT event loop and only works on GNOME and XFCE.
 * Qt and KDE use XSMP (via libSM).
 * No idea what happens on Wayland, but XSMP might be broken there.

If my understanding is correct, a comprehensive solution would have to provide both D-Bus and XSMP session clients in addition to SIGTERM and SIGHUP handlers.

Also, the semantics of SWT.Close event from Display need clarification.
The way I see it, SWT.Close is not intended to be a cleanup hook. It exists to provide shutdown cancellation opportunity (if cancellation is possible at all). SWT must guarantee that display is disposed during logout/shutdown, then cleanup can happen in Shell Dispose or Display Dispose or after the main loop.

Lars, I won't be working on this. This should be handled by someone more familiar with GTK, X and Wayland.
Comment 4 Alexander Kurtakov CLA 2018-02-27 08:24:16 EST
For the record: GTK2 support is in deep maintenance mode so don't bother with it at all.
Comment 5 Leo Ufimtsev CLA 2018-02-27 09:52:18 EST
For reference:
On the SWT/gtk side we have DBus support:
org.eclipse.swt.internal.GDBus
It's currently used to listen to OpenFile and OpenURL method invocations from equinox launcher.

It could potentially be modified to listen to "RequestStop" signal, which is emitted by systemd. Sources:
[1] https://www.freedesktop.org/wiki/Software/systemd/dbus/
[2] https://github.com/systemd/systemd/blob/master/NEWS  (See Controller)
[3] https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/   (see SIGTERM)
Comment 6 Eclipse Genie CLA 2019-04-17 14:04:05 EDT
New Gerrit change created: https://git.eclipse.org/r/140779
Comment 7 Alexandr Miloslavskiy CLA 2019-04-17 14:04:23 EDT
Tested on Ubuntu 16.04 (Gnome) - works.

Tested on Ubuntu 18.10 (Gnome) - works.

Tested on Fedora 29 (XFCE) - works.
Comment 8 Alexandr Miloslavskiy CLA 2019-04-17 16:17:23 EDT
Created attachment 278320 [details]
Test snippet
Comment 9 Eric Williams CLA 2019-04-18 10:16:01 EDT
(In reply to Alexandr Miloslavskiy from comment #8)
> Created attachment 278320 [details]
> Test snippet

What are the steps required to test with this snippet?
Comment 10 Alexandr Miloslavskiy CLA 2019-04-18 10:17:04 EDT
Open it and try to logout.
Comment 12 Eric Williams CLA 2019-04-24 22:16:00 EDT
I think this is a good candidate for an N&N entry. Alexandr, can you please prepare one? Here is a guide: https://wiki.eclipse.org/SWT/Devel/Workflow#Writing_new_and_noteworthy_.28N.26N.29_posts

You can look for my commits in that repo to see where the SWT ones go.
Comment 13 Eclipse Genie CLA 2019-04-25 03:57:05 EDT
New Gerrit change created: https://git.eclipse.org/r/141115
Comment 14 Eclipse Genie CLA 2019-04-25 11:14:22 EDT
New Gerrit change created: https://git.eclipse.org/r/141154
Comment 16 Eclipse Genie CLA 2019-04-29 06:08:27 EDT
New Gerrit change created: https://git.eclipse.org/r/141315
Comment 17 Andrey Loskutov CLA 2019-04-29 06:39:50 EDT
I observe now following errors printed to console after Eclipse startup:

SWT SessionManagerDBus: Failed to connect to SessionManager (gnome: Service not present, xcfe: Service not present)

I'm on KDE / RHEL 7.4.
Comment 18 Alexandr Miloslavskiy CLA 2019-04-29 07:45:14 EDT
This is expected if indeed both session managers are not available. Do you mean that the error should be silenced?
Comment 19 Alexandr Miloslavskiy CLA 2019-04-29 08:01:45 EDT
I have tested with Eclipse IBuild. With this patch, Eclipse now notices logoff and saves settings before the logout. The easiest way to test is to check whether window position is saved. 2019-03 doesn't notice the logout and window position is not saved.
Comment 20 Andrey Loskutov CLA 2019-04-29 08:22:12 EDT
(In reply to Alexandr Miloslavskiy from comment #18)
> This is expected if indeed both session managers are not available. Do you
> mean that the error should be silenced?

So the patch only supports gnome and xfce? Is there a way to disable this patch for KDE, if KDE is not supported (or fix the patch to work with KDE too)?
Comment 21 Alexandr Miloslavskiy CLA 2019-04-29 08:25:10 EDT
Doing research for KDE is probably beyond my time allocation for this task. As for disabling it, there's no need: it disables itself when it fails to find supported GNOME / XFCE. In this case the error message is printed.
Comment 22 Andrey Loskutov CLA 2019-04-29 08:27:38 EDT
(In reply to Alexandr Miloslavskiy from comment #21)
> Doing research for KDE is probably beyond my time allocation for this task.
> As for disabling it, there's no need: it disables itself when it fails to
> find supported GNOME / XFCE. In this case the error message is printed.

OK, can we mute the message if we detect KDE?
Comment 24 Andrey Loskutov CLA 2019-04-29 08:28:44 EDT
(In reply to Andrey Loskutov from comment #22)
> OK, can we mute the message if we detect KDE?

I mean , if we detect *any* unsupported window manager / desktop environment?
Comment 25 Alexandr Miloslavskiy CLA 2019-04-29 08:29:47 EDT
Yes, I will prepare the patch.
Comment 26 Eclipse Genie CLA 2019-04-29 09:10:53 EDT
New Gerrit change created: https://git.eclipse.org/r/141325
Comment 28 Eric Williams CLA 2019-05-01 10:10:28 EDT
Marking as fixed.
Comment 29 Eric Williams CLA 2019-05-21 14:59:48 EDT
Verified in I20190521-0600.