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*/ |
---|
32 | static int |
---|
33 | ignoreErrors (dpy, event) |
---|
34 | Display *dpy; |
---|
35 | XErrorEvent *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 | |
---|
46 | static |
---|
47 | killWindows (dpy, window) |
---|
48 | Display *dpy; |
---|
49 | Window 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 | |
---|
66 | static Jmp_buf resetJmp; |
---|
67 | |
---|
68 | /* ARGSUSED */ |
---|
69 | static SIGVAL |
---|
70 | abortReset (n) |
---|
71 | int n; |
---|
72 | { |
---|
73 | Longjmp (resetJmp, 1); |
---|
74 | } |
---|
75 | |
---|
76 | /* |
---|
77 | * this display connection better not have any windows... |
---|
78 | */ |
---|
79 | |
---|
80 | pseudoReset (dpy) |
---|
81 | Display *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 | } |
---|