You are not logged in.

#1 2014-04-03 08:44:29

lviggiani
Member
Registered: 2014-02-28
Posts: 141

Gently close all programs during shut down from Gnome Shell

Hi,
I noticed that when I shut down (or either reboot) my system, running programs are not "gently" closed. For example Google Chrome, next time I'll run it, will complain that the session was not closed correctly and offers me to restore previous tabs etc.

Analyzing what happen when I shut down the computer, I see:

1. X/GDM is immediately closed (screen goes black and switches to console mode)
2. A message "Sending SIGTERM to remaining processes" is immediately followed by "Sending SIGKILL to remaining processes"

According to what I've read so far, SIGTERM is the chance for a process to end gracefully. If it will not respond within a given timeout, SIGKILL will terminate it in a "rough manner".

So I tried killing chrome like this 'killall -SIGTERM chrome' and it closes gracefully (It will not complain about broken session next time I start it again). On the other hand, If I try to kill it with -SIGKILL, it will then complain.

So,where is the issue?

1. Is GDM not sending SIGTERM to programs like chrome or
2. Is systemd that sends SIGKILL to GDM to early not giving it the time to close its children?

Anyone else has the same issue?

Offline

#2 2014-04-03 11:07:40

diraimondo
Member
Registered: 2014-03-28
Posts: 61

Re: Gently close all programs during shut down from Gnome Shell

Yes, I confirm such behavior. It is annoying and it is supposed to work in a gentle manner.

Offline

#3 2014-04-03 12:43:11

Weegee
Member
Registered: 2010-08-06
Posts: 62

Re: Gently close all programs during shut down from Gnome Shell

Most of my applications already get killed even if I'm still in the shutdown dialogue, without having pressed the Shutdown button. And after that, I have the same behaviour as you described.


~

Offline

#4 2014-04-03 22:17:08

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 649

Re: Gently close all programs during shut down from Gnome Shell

diraimondo wrote:

Yes, I confirm such behavior. It is annoying and it is supposed to work in a gentle manner.

Google Chrome never used to have this issue, it started about 1 month ago. Given I use Chrome beta version I assumed it was a Chrome bug but with the post here I now realise it may be an Arch/GNOME bug?

That explains why there has been about 3 Chrome beta updates in that time and I have been surprised each time that this bug has not been addressed.

Offline

#5 2014-05-01 04:23:50

bulletmark
Member
From: Brisbane, Australia
Registered: 2013-10-22
Posts: 649

Re: Gently close all programs during shut down from Gnome Shell

This bug is a pain and doesn't seem to be going away in a hurry. I see that the OP has also raised it on stackexchange but there is not much help there either. I looked around the GNOME/gdm bug list but couldn't find anything. Anybody have any further reference, e.g. a bug I can at least star?

Offline

#6 2014-07-14 12:46:31

kas21
Member
Registered: 2014-02-07
Posts: 12

Re: Gently close all programs during shut down from Gnome Shell

Is anyone aware of a fix for this issue?  I am experiencing this as well and have not come across a solution.

Offline

#7 2014-07-14 16:34:45

cris9288
Member
Registered: 2013-01-07
Posts: 348

Re: Gently close all programs during shut down from Gnome Shell

I use gnome and only get the described behavior when shutting down/rebooting with systemctl poweroff/reboot. So instead, I've been trying to power off either from the system menu or control+alt+delete.

Offline

#8 2014-07-14 17:21:13

TheGuyWithTheFace
Member
Registered: 2012-12-09
Posts: 113

Re: Gently close all programs during shut down from Gnome Shell

I'm not sure this is Gnome-specific. I experience the same behavior on KDE - I'm not sure if it's related or not though.

Offline

#9 2014-07-14 18:49:26

Pse
Member
Registered: 2008-03-15
Posts: 413

Re: Gently close all programs during shut down from Gnome Shell

I thought DEs sent SIGTERM to processes launched in them before telling the display manager to close the session. If that's not the case, it sucks.

Offline

#10 2014-07-14 19:02:04

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Gently close all programs during shut down from Gnome Shell

Pse wrote:

I thought DEs sent SIGTERM to processes ...

I don't know about DEs, but some window managers will - in fact there is a yet-gentler method many will use as not all programs listen for SIGTERM.  A 'best' approach would be to first send a delete window message to every client with open windows, then to send a SIGTERM to anything that remained.  Some X programs will have signal handlers, but they will all have an event handler (for something like 'delete-window').


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2014-07-15 06:01:20

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Gently close all programs during shut down from Gnome Shell

I experienced the same behaviour with Chromium, Openbox and startx (no display manager) a few months ago and addressed it in the Chromium bug tracker. However, to me it is still not clear what is the real cause of the issue.

https://code.google.com/p/chromium/issu … ?id=358143

Offline

#12 2014-07-15 16:19:36

TheGuyWithTheFace
Member
Registered: 2012-12-09
Posts: 113

Re: Gently close all programs during shut down from Gnome Shell

I don't think it's specific to chromium - many other programs I use complain of being shut down incorrectly, for example LibreOffice. Whatever the issue is, I have a hunch it's not caused by any specific user program.

Offline

#13 2014-07-15 16:34:03

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Gently close all programs during shut down from Gnome Shell

If anyone is interested, this can be compiled and called from the end of an xinitrc (after a window manager exits) and it should solve this for most client programs:

/* Xkill sample code by Jesse McClure
 * Released to public domain
 *
 * COMPILE:
 * gcc -o xkill xkill.c -lX11
 */

#include <X11/Xlib.h>

int main() {
	Display *dpy = XOpenDisplay(0x0);
	if (!dpy) return 1;
	Window root = DefaultRootWindow(dpy);
	Window ignore, *win;
	unsigned int nwin;
	XQueryTree(dpy, root, &ignore, &ignore, &win, &nwin);
	while (nwin) XKillClient(dpy, win[(--nwin)]);
	if (win) XFree(win);
	XCloseDisplay(dpy);
	return 0;
}

This may not work with some gtk (particularly gtk3) windows which seem to ignore standard X11 calls and need a more complicated sendevent system - but this is a basic example.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#14 2014-07-16 05:49:50

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Gently close all programs during shut down from Gnome Shell

@Trilby

Very nice, thanks!

Can this be made a package for the AUR?

Offline

#15 2014-07-16 11:43:44

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Gently close all programs during shut down from Gnome Shell

It seems a little small/simple for a package.  But if you'd like to package it, feel free.  I tossed it up on my github here: https://raw.githubusercontent.com/Trilb … er/xkill.c

However, like I mentioned, there are a some cases where this just will not work at all.  I know roughly what would need to be added to make it more comprehensive - but it's not really a project I can commit to polishing and maintaining.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#16 2014-07-18 12:13:38

Baryon
Member
Registered: 2011-08-12
Posts: 72

Re: Gently close all programs during shut down from Gnome Shell

Yes it happens with systemctl poweroff - in that case, shouldn't it be reported to systemd?

Offline

#17 2014-07-18 12:54:01

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Gently close all programs during shut down from Gnome Shell

Baryon, systemd does not and should not need to know about X11 client programs.  Systemd sends a SIGTERM and SIGKILL to all processes.  If those processes do not catch those signals, then if there is a bug at all, it is with those client programs.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#18 2014-07-18 13:18:32

Baryon
Member
Registered: 2011-08-12
Posts: 72

Re: Gently close all programs during shut down from Gnome Shell

OK... I thought the problem might be that it sends SIGKILL too quickly, i.e. killing everything before they have a chance to shutdown properly.

Offline

#19 2014-07-19 09:42:00

Awebb
Member
Registered: 2010-05-06
Posts: 6,272

Re: Gently close all programs during shut down from Gnome Shell

No, the culprit is the browser. There is nothing about a web browser with understandable reasons for not promptly killing itself upon receiving either the command from X to kill its window or a SIGTERM. Anything this browser does after the main window is gone, is due to profound design flaws. It is not systemd's business to ponder about malicious user software. However, since systemd has such a seat and session fixation, it would be nice of Gnome to properly report, that the session has been ended before issuing a shutdown. But however you twist and bend it, that browser of yours is broken.

Offline

#20 2014-07-19 14:57:00

Pse
Member
Registered: 2008-03-15
Posts: 413

Re: Gently close all programs during shut down from Gnome Shell

Awebb wrote:

No, the culprit is the browser. There is nothing about a web browser with understandable reasons for not promptly killing itself upon receiving either the command from X to kill its window or a SIGTERM. Anything this browser does after the main window is gone, is due to profound design flaws. It is not systemd's business to ponder about malicious user software. However, since systemd has such a seat and session fixation, it would be nice of Gnome to properly report, that the session has been ended before issuing a shutdown. But however you twist and bend it, that browser of yours is broken.

I don't see how Chrome (or any other browser) is broken for taking a bit to shut down properly. Files need to be closed, locks need unlocking, several processes need to close (process-per-tab-group), caches need to be dumped to disk, mmaped files need committing to disk, etc. In my tests, Chromium takes roughly a second to shut down with hundreds of tabs opened, which IMO is reasonable.

Last edited by Pse (2014-07-19 14:57:56)

Offline

#21 2014-07-19 15:20:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Gently close all programs during shut down from Gnome Shell

We can speculate all we want, but more data is needed to make any conclusions.  The problem *could* be at any one of the following:

1) browsers / other client programs don't accept X11 messages to shut down.  This would be a bug in that client program and should be reported.  This is also highly unlikely.

2) brosers / other client programs would accept X11 messages to shut down, but nothing is sending them.  The clients don't handle SIGTERM signals.  A feature request could be made to the clients to handle a SIGTERM the same way they would a X11 shut down message - this would be easy for them to implement, but in many cases X11 programs do not do this by default because they expect a message from the WM (see #4).

3) WMs/DEs aren't sending X11 messages to shutdown their clients.  I'd consider this a bug and it should be reported to the WM devs.  This could be diagnoses if a shutdown through the WM/DE tools leaves browsers in an 'unclean' shutdown state.

4) If a normal WM shutdown works as desired, but a `systemctl shutdown/poweroff` leaves the browser in an unclean state, this is simply because the WM/DE isn't catching SIGTERM signals.  The WM is sending the appropriate messages to client programs when it is shutdown, but the WM never gets the message to shutdown.  This could be a feature request to WM/DE devs to handle the SIGTERM signal to trigger a clean shutdown.  This would be trivially easy to add to any WM, and this would be my suggested approach.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#22 2014-07-19 16:26:17

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Gently close all programs during shut down from Gnome Shell

For all of you who want to test Trilby's suggested approach, I created the xkillall package. Users of startx need to add the command after launching the WM/DE:

# ~/.xinitrc excerpt
openbox-session
xkillall

Last edited by orschiro (2014-07-19 23:22:59)

Offline

#23 2014-07-19 16:59:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: Gently close all programs during shut down from Gnome Shell

You'd have to get rid of the "exec" infront of the WM, otherwise the xkillall command will never execute.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#24 2014-07-19 23:23:38

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Gently close all programs during shut down from Gnome Shell

@Trilby

And I thought it was a mistake in your mail. Edited my post.

Thanks wink

Offline

#25 2014-07-20 04:36:41

silverhammermba
Wiki Maintainer
Registered: 2011-04-14
Posts: 156

Re: Gently close all programs during shut down from Gnome Shell

I have noticed this problem is well. You would think that X11 would have some built-in "close all windows, then exit" command and not just "ohshitshutdowneverything."

Offline

Board footer

Powered by FluxBB