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

shutdown from gnome logout dialog


I've been reading some recent threads on this list proposing solutions
to make it possible to shutdown (or reboot) their workstation directly
from the gnome session logout dialog.

Some solutions proposed were based on some sudo wrapper (or PAM trick) called by gnome-session at logout time. This setup has some drawbacks since it gives the ability of shutting down the server to more people than necessary for this feature. Moreover the gdm PostSession script might not be ran. Making gdm do the shutdown itself at session logout avoid some permission related problems.

Here is the principle I propose :
 - at logout, gnome-session proposes the reboot and halt options to the user
 - if halt [or reboot] is chosen, a $HOME/.gdm-halt file [or .gdm-reboot]
   file is created
 - in the gdm PostSession script (which is run by gdm as root), the
   existence of those files is tested
 - if one of them exists and if the configuration allows, shutdown
   (or reboot) of the workstation is triggered

I discussed the thing a bit with gdm maintainer <jirka@5z.com>, in July. Some better solution can be designed (using /tmp/.gdm_socket as a communication link, instead of env variables and files), but he said this was Gnome 2.6 stuff. He suggested that I should fill a gnome bugzilla bug to get a proper solution done for Gnome 2.6.

(this answers a bit Sven's question about upstream plans)

This solution is surely a bit "hacky", but the result is very user
friendly I think.

Some more details:
  - checks are done so that shutdown cannot be done if gdm session
    is not local
  - shutdown or reboot is only made if the right option is set
    in /etc/default/gdm AND if SystemMenu is true in gdm.conf
    AND SecureSystemMenu is false.
  - gnome-session is lightly modified : it presents the shutdown/reboot
    options only if relevant (it checks an environement variable
    set in gdm Session init script).

Attached are :
  - the patch to gnome-session (actually to the gnome-session debian
    package source, 2.2.2-4 )
  - the different scripts and files (tar reproducing the place of the
    different files in a real filesystem)

I'd be very happy to have some feedback; feel free to send yours.
If people find this nice enough, that'd be great if it could get included in
official packages (gdm for the script, and gnome-session for the patch).



PS: I'm not the first to propose such a setup, after setting it up, I saw a report in the BTS proposing more or less the same thing; I don't know for which package it was submitted, and I can't manage to find it...

== tom@treizh.net
== PGP/keyID: 8CEA233D
== PGP/KeyFP: 503BF6CFD3AE8719377B832A02FB94E08CEA233D

diff -ru gnome-session-2.2.2/debian/rules gnome-session-2.2.2-4-hacked/debian/rules
--- gnome-session-2.2.2/debian/rules	2003-09-15 20:39:52.000000000 +0200
+++ gnome-session-2.2.2-4-hacked/debian/rules	2003-09-15 19:56:07.000000000 +0200
@@ -28,6 +28,8 @@
 	./configure --prefix=/usr --sysconfdir=/etc --mandir=\$${prefix}/share/man \
+	--with-reboot-command=/usr/bin/ask.gdm.reboot \
+	--with-halt-command=/usr/bin/ask.gdm.halt \
 	--localstatedir=/var/lib --with-window-manager=sawfish \
 	--host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
diff -ru gnome-session-2.2.2/gnome-session/logout.c gnome-session-2.2.2-4-hacked/gnome-session/logout.c
--- gnome-session-2.2.2/gnome-session/logout.c	2002-10-15 08:05:01.000000000 +0200
+++ gnome-session-2.2.2-4-hacked/gnome-session/logout.c	2003-09-15 20:16:58.000000000 +0200
@@ -302,14 +302,13 @@
 			  FALSE, TRUE, 0);
-  /* Red Hat specific code to check if the user has a
+  /* Debian specific code to check if the user has a
    * good chance of being able to shutdown the system,
    * and if so, give them that option
-  s = g_strconcat ("/var/lock/console/", g_get_user_name (), NULL);
-  t = g_strconcat ("/var/run/console/", g_get_user_name (), NULL);
-  if (((geteuid () == 0) || g_file_exists (t) || g_file_exists(s)) &&
-      access (halt_command[0], X_OK) == 0)
+  if ( getenv("GDM_WOULD_SHUTDOWN") != NULL &&
+      access (reboot_command[0], X_OK) == 0 &&
+      access (halt_command[0], X_OK) == 0 )
       GtkWidget *frame;
       GtkWidget *action_vbox;
@@ -332,8 +331,6 @@
       r = reboot = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (r), _("_Restart the computer"));
       gtk_box_pack_start (GTK_BOX (action_vbox), r, FALSE, FALSE, 0);
-  g_free (s);
-  g_free (t);
   gsm_center_window_on_screen (GTK_WINDOW (box), screen, monitor);

Attachment: gdm-shutdown-from-gnome.tar.gz
Description: Unix tar archive

Reply to: