2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
25 * (c) Copyright 1993, 1994 International Business Machines Corp. *
26 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
27 * (c) Copyright 1993, 1994 Novell, Inc. *
30 * xdm - display manager daemon
32 * $XConsortium: reset.c /main/4 1995/10/27 16:14:40 rswiston $
34 * Copyright 1988 Massachusetts Institute of Technology
36 * Permission to use, copy, modify, and distribute this software and its
37 * documentation for any purpose and without fee is hereby granted, provided
38 * that the above copyright notice appear in all copies and that both that
39 * copyright notice and this permission notice appear in supporting
40 * documentation, and that the name of M.I.T. not be used in advertising or
41 * publicity pertaining to distribution of the software without specific,
42 * written prior permission. M.I.T. makes no representations about the
43 * suitability of this software for any purpose. It is provided "as is"
44 * without express or implied warranty.
46 * Author: Keith Packard, MIT X Consortium
50 * pseudoReset -- pretend to reset the server by killing all clients
51 * with windows. It will reset the server most of the time, unless
52 * a client remains connected with no windows.
56 # include <sys/types.h>
57 # include <sys/signal.h>
62 /***************************************************************************
64 * Local procedure declarations
66 ***************************************************************************/
68 static SIGVAL abortReset( int arg ) ;
69 static int ignoreErrors( Display *dpy, XErrorEvent *event) ;
70 static void killWindows( Display *dpy, Window window) ;
74 /***************************************************************************
78 ***************************************************************************/
82 ignoreErrors( Display *dpy, XErrorEvent *event )
84 Debug ("Ignoring error...\n");
89 * this is mostly bogus -- but quite useful. I wish the protocol
90 * had some way of enumerating and identifying clients, that way
91 * this code wouldn't have to be this kludgy.
95 killWindows( Display *dpy, Window window )
97 Window root, parent, *children;
99 unsigned int nchildren = 0;
101 while (XQueryTree (dpy, window, &root, &parent, &children, &nchildren)
104 for (child = 0; child < nchildren; child++) {
105 Debug ("Calling XKillClient() for window 0x%x\n",
107 XKillClient (dpy, children[child]);
109 XFree ((char *)children);
113 static jmp_buf resetJmp;
116 abortReset( int arg )
118 longjmp (resetJmp, 1);
122 * this display connection better not have any windows...
126 pseudoReset( Display *dpy )
131 if (setjmp (resetJmp)) {
133 ReadCatalog(MC_LOG_SET,MC_LOG_PSEUDO,MC_DEF_LOG_PSEUDO));
135 signal (SIGALRM, abortReset);
137 XSetErrorHandler (ignoreErrors);
138 for (screen = 0; screen < ScreenCount (dpy); screen++) {
139 Debug ("Pseudo reset screen %d\n", screen);
140 root = RootWindow (dpy, screen);
141 killWindows (dpy, root);
143 Debug ("Before XSync\n");
147 signal (SIGALRM, SIG_DFL);
148 XSetErrorHandler ((int (*)()) 0);
149 Debug ("pseudoReset() done\n");