Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kdm / backend / reset.c
blob8f380b58d8366fe12d0a3876e13787b5edd6c91b
1 /*
3 Copyright 1988, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of a copyright holder shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
25 from the copyright holder.
30 * xdm - display manager daemon
31 * Author: Keith Packard, MIT X Consortium
33 * pseudoReset -- pretend to reset the server by killing all clients
34 * with windows. It will reset the server most of the time, unless
35 * a client remains connected with no windows.
38 #include "dm.h"
39 #include "dm_error.h"
41 #include <X11/Xlib.h>
43 #include <signal.h>
45 /*ARGSUSED*/
46 static int
47 ignoreErrors( Display *dspl ATTR_UNUSED, XErrorEvent *event ATTR_UNUSED )
49 debug( "ignoring error\n" );
50 return False;
54 * this is mostly bogus -- but quite useful. I wish the protocol
55 * had some way of enumerating and identifying clients, that way
56 * this code wouldn't have to be this kludgy.
59 static void
60 killWindows( Window window )
62 Window root, parent, *children;
63 unsigned int child, nchildren = 0;
65 while (XQueryTree( dpy, window, &root, &parent, &children, &nchildren ) &&
66 nchildren > 0)
68 for (child = 0; child < nchildren; child++) {
69 debug( "XKillClient %p\n", children[child] );
70 XKillClient( dpy, children[child] );
72 XFree( (char *)children );
76 static Jmp_buf resetJmp;
78 /* ARGSUSED */
79 static void
80 abortReset( int n ATTR_UNUSED )
82 Longjmp( resetJmp, 1 );
86 * this display connection better not have any windows...
89 void
90 pseudoReset()
92 int screen;
94 if (Setjmp( resetJmp )) {
95 logError( "pseudoReset timeout\n" );
96 } else {
97 (void)Signal( SIGALRM, abortReset );
98 (void)alarm( 30 );
99 XSetErrorHandler( ignoreErrors );
100 for (screen = 0; screen < ScreenCount (dpy); screen++) {
101 debug( "pseudoReset screen %d\n", screen );
102 killWindows( RootWindow( dpy, screen ) );
104 debug( "before XSync\n" );
105 XSync( dpy, False );
106 (void)alarm( 0 );
108 Signal( SIGALRM, SIG_DFL );
109 XSetErrorHandler( (XErrorHandler)0 );
110 debug( "pseudoReset done\n" );