source: trunk/athena/etc/xdm/xdm/reset.c @ 6052

Revision 6052, 2.5 KB checked in by lwvanels, 33 years ago (diff)
Initial revision
Line 
1/*
2 * xdm - display manager daemon
3 *
4 * $XConsortium: reset.c,v 1.10 91/09/19 16:26:03 keith Exp $
5 *
6 * Copyright 1988 Massachusetts Institute of Technology
7 *
8 * Permission to use, copy, modify, and distribute this software and its
9 * documentation for any purpose and without fee is hereby granted, provided
10 * that the above copyright notice appear in all copies and that both that
11 * copyright notice and this permission notice appear in supporting
12 * documentation, and that the name of M.I.T. not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission.  M.I.T. makes no representations about the
15 * suitability of this software for any purpose.  It is provided "as is"
16 * without express or implied warranty.
17 *
18 * Author:  Keith Packard, MIT X Consortium
19 */
20
21/*
22 * pseudoReset -- pretend to reset the server by killing all clients
23 * with windows.  It will reset the server most of the time, unless
24 * a client remains connected with no windows.
25 */
26
27# include       "dm.h"
28# include       <X11/Xlib.h>
29# include       <signal.h>
30
31/*ARGSUSED*/
32static int
33ignoreErrors (dpy, event)
34Display *dpy;
35XErrorEvent     *event;
36{
37        Debug ("ignoring error\n");
38}
39
40/*
41 * this is mostly bogus -- but quite useful.  I wish the protocol
42 * had some way of enumerating and identifying clients, that way
43 * this code wouldn't have to be this kludgy.
44 */
45
46static
47killWindows (dpy, window)
48Display *dpy;
49Window  window;
50{
51        Window  root, parent, *children;
52        int     child;
53        unsigned int nchildren = 0;
54       
55        while (XQueryTree (dpy, window, &root, &parent, &children, &nchildren)
56               && nchildren > 0)
57        {
58                for (child = 0; child < nchildren; child++) {
59                        Debug ("XKillClient 0x%x\n", children[child]);
60                        XKillClient (dpy, children[child]);
61                }
62                XFree ((char *)children);
63        }
64}
65
66static Jmp_buf  resetJmp;
67
68/* ARGSUSED */
69static SIGVAL
70abortReset (n)
71    int n;
72{
73        Longjmp (resetJmp, 1);
74}
75
76/*
77 * this display connection better not have any windows...
78 */
79 
80pseudoReset (dpy)
81Display *dpy;
82{
83        Window  root;
84        int     screen;
85
86        if (Setjmp (resetJmp)) {
87                LogError ("pseudoReset timeout\n");
88        } else {
89                (void) Signal (SIGALRM, abortReset);
90                (void) alarm (30);
91                XSetErrorHandler (ignoreErrors);
92                for (screen = 0; screen < ScreenCount (dpy); screen++) {
93                        Debug ("pseudoReset screen %d\n", screen);
94                        root = RootWindow (dpy, screen);
95                        killWindows (dpy, root);
96                }
97                Debug ("before XSync\n");
98                XSync (dpy, False);
99                (void) alarm (0);
100        }
101        Signal (SIGALRM, SIG_DFL);
102        XSetErrorHandler ((int (*)()) 0);
103        Debug ("pseudoReset done\n");
104}
Note: See TracBrowser for help on using the repository browser.