Re: gnome-session: how to shutdown gnome-session from root?



On date Saturday 2006-12-09 01:42:13 +0530, Ritesh Khadgaray wrote:
> On Fri, 2006-12-08 at 19:33 +0100, Stefano Sabatini wrote:
> > Hi Ritesh, and thanks for your reply.
> > 
> > On date Friday 2006-12-08 22:22:35 +0530, Ritesh Khadgaray wrote:
> > > On Fri, 2006-12-08 at 15:43 +0100, Stefano Sabatini wrote:
> > > > Hi all, 
> > > > 
> > > > I would like like to setup acpid to automatically launch the
> > > > gnome-session-save program when the power button is pressed (and gnome
> > > > is running).
> 
> there were talks with gnome-power-manager on this. not too sure, where
> or what it was about.
> 

gnome-power-manager is very fine, and it supports out of the box the
power button event, that triggers the very gnome-session-save --kill
command.

The only problem is that it isn't as configurable as a script (I can't
actually change the command executed for each event).

> try using dbus system wide service. 
> http://cvs.gnome.org/viewcvs/*checkout*/gnome-power-manager/docs/dbus-interface.html
> 
> python scripts are your friend.
> 

I should actually send a message to the gnome-session process using
D-bus, and I actually don't know very well neither the D-bus
communication model, neither python programming :-(...

In each case, while the D-bus/python scripting seems to be the "right"
solution (or maybe even some dbus-send command could be sufficient?)
I've worked around the following fix, maybe a little too
"overkilling", that manages either the case when gnome-power-manager
is not installed.

1) added in the startup programs list (gnome-session-properties) the
command:
echo $SESSION_MANAGER > ~/tmp/gnome-session-manager

2) wrote this script and placed it in /usr/local/sbin/kill-gnome-session

#! /bin/bash
set -e

gnome_session_user=$(ps -e -o command,user | awk '/gnome-session/ { print $2 }')
SESSION_MANAGER=$(cat /home/$gnome_session_user/tmp/gnome-session-manager)

export SESSION_MANAGER
gnome-session-save --gui --kill

3) modified the /etc/acpi/power-button script in this way: 
#! /bin/bash
# Initiates a shutdown when the power putton is pressed.

if ps -e -o command | grep -q '[k]desktop'; then
    kdesktop="on"
fi
if ps -e o command | grep -q '[g]nome-session'; then
    gnome_session="on"
fi
if  ps -e o command | grep -q '[g]nome-power-manager'; then
    gnome_power_manager="on"
fi

if [ "$kdesktop" ] && [ -f /usr/bin/dcop ]; then
    dcop --all-sessions --all-users ksmserver ksmserver logout 0 2 0 && exit 0
elif [ "$gnome_session" ]; then 
    if [ "$gnome_power_manager" ]; then         
    # don't do nothing: gnome-manager knows what to do         
        true
    elif [ -f /usr/bin/gnome-session-save ]; then
        kill-gnome-session
    fi
else
    /sbin/shutdown -h now "Power button pressed"
fi

Cheers
-- 
Stefano Sabatini
Linux user number 337176 (see http://li.count.org)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]