~ubuntu-branches/ubuntu/feisty/xdm/feisty

« back to all changes in this revision

Viewing changes to reset.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2005-09-08 09:43:15 UTC
  • Revision ID: james.westby@ubuntu.com-20050908094315-ceggae9y1p4fgvia
Tags: upstream-0.99.1
ImportĀ upstreamĀ versionĀ 0.99.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: reset.c,v 1.4 2001/02/09 02:05:40 xorgcvs Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1988, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
21
OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall
 
24
not be used in advertising or otherwise to promote the sale, use or
 
25
other dealings in this Software without prior written authorization
 
26
from The Open Group.
 
27
 
 
28
*/
 
29
/* $XFree86: xc/programs/xdm/reset.c,v 1.3 2001/01/17 23:45:21 dawes Exp $ */
 
30
 
 
31
/*
 
32
 * xdm - display manager daemon
 
33
 * Author:  Keith Packard, MIT X Consortium
 
34
 *
 
35
 * pseudoReset -- pretend to reset the server by killing all clients
 
36
 * with windows.  It will reset the server most of the time, unless
 
37
 * a client remains connected with no windows.
 
38
 */
 
39
 
 
40
# include       "dm.h"
 
41
# include       "dm_error.h"
 
42
 
 
43
# include       <X11/Xlib.h>
 
44
# include       <signal.h>
 
45
 
 
46
/*ARGSUSED*/
 
47
static int
 
48
ignoreErrors (Display *dpy, XErrorEvent *event)
 
49
{
 
50
        Debug ("ignoring error\n");
 
51
        return 0;
 
52
}
 
53
 
 
54
/*
 
55
 * this is mostly bogus -- but quite useful.  I wish the protocol
 
56
 * had some way of enumerating and identifying clients, that way
 
57
 * this code wouldn't have to be this kludgy.
 
58
 */
 
59
 
 
60
static void
 
61
killWindows (Display *dpy, Window window)
 
62
{
 
63
        Window  root, parent, *children;
 
64
        int     child;
 
65
        unsigned int nchildren = 0;
 
66
        
 
67
        while (XQueryTree (dpy, window, &root, &parent, &children, &nchildren)
 
68
               && nchildren > 0)
 
69
        {
 
70
                for (child = 0; child < nchildren; child++) {
 
71
                        Debug ("XKillClient 0x%lx\n", (unsigned long)children[child]);
 
72
                        XKillClient (dpy, children[child]);
 
73
                }
 
74
                XFree ((char *)children);
 
75
        }
 
76
}
 
77
 
 
78
static Jmp_buf  resetJmp;
 
79
 
 
80
/* ARGSUSED */
 
81
static SIGVAL
 
82
abortReset (int n)
 
83
{
 
84
        Longjmp (resetJmp, 1);
 
85
}
 
86
 
 
87
/*
 
88
 * this display connection better not have any windows...
 
89
 */
 
90
 
 
91
void
 
92
pseudoReset (Display *dpy)
 
93
{
 
94
        Window  root;
 
95
        int     screen;
 
96
 
 
97
        if (Setjmp (resetJmp)) {
 
98
                LogError ("pseudoReset timeout\n");
 
99
        } else {
 
100
                (void) Signal (SIGALRM, abortReset);
 
101
                (void) alarm (30);
 
102
                XSetErrorHandler (ignoreErrors);
 
103
                for (screen = 0; screen < ScreenCount (dpy); screen++) {
 
104
                        Debug ("pseudoReset screen %d\n", screen);
 
105
                        root = RootWindow (dpy, screen);
 
106
                        killWindows (dpy, root);
 
107
                }
 
108
                Debug ("before XSync\n");
 
109
                XSync (dpy, False);
 
110
                (void) alarm (0);
 
111
        }
 
112
        Signal (SIGALRM, SIG_DFL);
 
113
        XSetErrorHandler ((XErrorHandler)0 );
 
114
        Debug ("pseudoReset done\n");
 
115
}