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

Re: system shutdown from xdm



> Dave Whiteley wrote:
> 
> > Now I am playing with my own linux systems, and I want to create a
> > similar user to give my Wife an easy way to shut down the PC.

I use the following solution to let my mom shut down the PC from xdm:

** Step 1: a short Xaw program.

#include <stdlib.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h> 
#include <X11/Xaw/Command.h> 

void run(Widget w, XtPointer data, XtPointer call)
{
    system("shutdown -h now");
    exit(0);
}

int main(int argc, char *argv[])
{
    Widget toplevel, button;

    toplevel = XtInitialize(argv[0], "simple", NULL, 0, &argc, argv);
    button = XtCreateManagedWidget("Shutdown",
	commandWidgetClass, toplevel, NULL, 0);
    XtAddCallback(button, XtNcallback, run, NULL);

    XtRealizeWidget(toplevel);
    XtMainLoop();
    exit(0);
}

to compile, 'apt-get install xlib6g-dev' and run:
gcc -O2 -Wall -L/usr/X11R6/lib -lXaw -lX11 xshutdown.c -o xshutdown

Note that this program is mostly cribbed from a 'Hello, world' sample
somewhere and segfaults if you try to send it a WM_DELETE; I'm working
on that. (I could do it in GTK[1], but the Xaw course notes I was using
have gone offline.) In other words don't trust this code to be the
definitive implementation.

** Step 2: start this up when the login widget is presented.
in xdm's Xsetup file (which should be in /etc/X11/xdm):

/root/xshutdown -bg gray -fn lucidasans-12 -geom -126+380 &
echo $! > /var/run/xshutdown.pid

** Step 3: kill it when a user sucessfully logs in.
in xdm's Xstartup file:

pid=$(cat /var/run/xshutdown.pid 2>/dev/null)
test "$pid" && kill $pid 2>/dev/null

(once again, syntax here is cribbed from how Debian's default
scripts[2] deal with xconsole (which I have disabled anyway). In this
case that should make it pretty solid though.)

Since the little Xaw proggie runs as root, it is allowed to shut down
the computer. There could be a security hole somewhere, but I'm not
going to get too concerned there.

[1] the problem with GTK is that it doesn't implement -geom, which I
use to but the shutdown button in the lower left corner of the login
widget (kludge! kludge!). You can also use +0-0 or -5-5 for the lower
left corner or 5 pixels from the lower right... read 'man X' and
experiment. plus GTK looks kinda silly without a window manager frame.

[2] except for the way I prefer to use to use 'test'. Syntactic sugar
rots your teeth! :-)

-- 
"Perfection [in design] is achieved not when there is nothing left to
add, but rather when there is nothing left to take away."
                                          -- Antoine de Saint-Exupery


Reply to: