Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have been banging my head against this for quite a while now. It's related to this question. I would like to find out exactly what happens when I choose to shut down my Linux box from the GUI. This seems to be poorly (if at all) documented.

Ideally, I'm hoping for a DE- and OS-agnostic answer. Barring that, I'm interested in the specific case of Mandriva 2010.1 and Debian 6.x (Squeeze) and 7.0 (Wheezy) all running Gnome. (If you're paying close attention, yes that's Gnome 2 and Gnome 3)

Basically, I would like to know which command/script/sequence of scripts is started when I press "Shut Down" or "Restart" so I can modify their behavior. Some forum posts I looked at suggest hacking /etc/polkit-1/* but this directory structure is only a skeleton on my Debian (Squeeze) box, for example.

Can anyone help?


EDIT

What I have tried so far

  • Replaced the shutdown executable with a script of my own. This doesn't work: when I press shutdown Gnome logs out without executing my script.
  • Tried editing the Gnome 2 menu. No joy: the "Shutdown", "Log out" and "Lock Screen" options do not appear in the menu editor.
  • Looked at /usr/share/menu, nothing helpful there.

Possible avenues for the solution

  • straceing the GUI options (is this even possible?)
  • Looking at shutdown's source code
  • Looking at gnome-session's source code

Update

As per my comments on the answer below, I have looked into polkit actions under /usr/share/polkit-1/actions/ and found (in the file org.freedesktop.consolekit.policy) an action called org.freedesktop.consolekit.system.stop-multiple-users that throws the message

System policy prevents stopping the system when other users are logged in

I'm thinking (due to the org.freedesktop.* naming convention) that this is some kind of signal sent to the DM via D-BUS. Moreover, this message appears when trying to shutdown graphically while other users are logged in, so the mechanism that triggers it must be the same mechanism triggered when "Shut Down" or "Power Off" is selected from the GUI.

Can anyone confirm/refute? Is there a possibility of somehow intercepting this signal or modifying it?

share|improve this question
    
What are you trying to accomplish? You might could add a edit /etc/init.d/rc.local to call a script when being stopped. –  depquid May 22 '13 at 19:10
    
@depquid What I'm trying to accomplish is in my older question which I linked to: I'm trying to prevent a locally-logged-in user from clobbering another user's SSH session. –  Joseph R. May 22 '13 at 20:05
add comment

1 Answer

up vote 6 down vote accepted

It depends on your Display Manager! (i.e. KDM, GDM)

Please bear in mind your DM runs as root! (it needs root privileges in order to run your session process as the user you log in)

When you click shutdown in KDE or GNOME, your DE sends a signal to your DM to power off or restart after the session has terminated. Then, your DE tells every program to end and once all other process has terminated (or expired a timeout), the last process of your DE -- the session process -- terminates.

The session process is the first process started in a X11 session. When it's killed or it terminates, the session terminates. Have you ever seen that xterm when running X without DE? That is a session process. This process is called kdeinit in KDE and gnome-session in GNOME.

Once the session has terminated, control is returned to your DM (which has been waiting for the X process to end), and it checks what the DE told him to do. If it told it to power off or restart, it will do that. In other case, it will just start a new login screen in X.

This is also related with problems you may have had in the past, with some DE not being able to power off or restart, just to log out, when used in combination with some other DMs.

In any case, this is not so bad documented. GDM has a manual page of a command which allows you to tell it to shutdown just like I told before (gdm-control). KDM has excellent documentation too and has a similar (a little more complex) utility named kdmctl.


Shutdown and restart is possible without PolicyKit, but PolicyKit serves many purposes needed on nowadays systems like mounting disks without being root, suspend or hibernate the computer. And it neither is bad documented!

Check out this if you want to know more about what is PolicyKit and how does it work: http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html

share|improve this answer
    
Sounds promising. Thanks for the links to the docs. I have no doubt these manuals are comprehensive and clear but they might as well not have existed. Your answer is the first time I've seen the display manager mentioned in conjunction with this issue, so it's not exactly common knowledge. I will try this and let you know... –  Joseph R. May 22 '13 at 20:08
    
OK. gdm-control was no help. The documentation your provided on the PolicyKit seems more promising. I'll dig into that and see if I can implement a custom rule. To be continued... –  Joseph R. May 22 '13 at 20:53
    
+1 ; Note, however, that gdm-control is part of openbox. It is not shipped with Gnome or GDM, nor was it written with Gnome in mind. –  don_crissti May 22 '13 at 21:33
    
I did some reading (skimming, more like) and please correct me if I'm wrong: the DE, when requested to shutdown, will send a message to the DM through the polkit on D-BUS. Pending authentication, the session may either be terminated or the request revoked. This is defined in a polkit action called org.freedesktop.consolekit.system.stop-multiple-users in /usr/share/polkit-1/actions It is set to revoke the request for inactive users and to auth_admin_keep for the active user. The question is, what defines this action? What exactly does it execute? –  Joseph R. May 23 '13 at 0:24
    
@don_crissti That much I now understand. What I'm interested in is precisely this "signal". What is the client that sends it? –  Joseph R. May 23 '13 at 22:09
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.