~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/backend/reset.c

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright 1988, 1998  The Open Group
 
4
 
 
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.
 
10
 
 
11
The above copyright notice and this permission notice shall be included
 
12
in all copies or substantial portions of the Software.
 
13
 
 
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.
 
21
 
 
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.
 
26
 
 
27
*/
 
28
 
 
29
/*
 
30
 * xdm - display manager daemon
 
31
 * Author: Keith Packard, MIT X Consortium
 
32
 *
 
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.
 
36
 */
 
37
 
 
38
#include "dm.h"
 
39
#include "dm_error.h"
 
40
 
 
41
#include <X11/Xlib.h>
 
42
 
 
43
#include <signal.h>
 
44
 
 
45
/*ARGSUSED*/
 
46
static int
 
47
ignoreErrors(Display *dspl ATTR_UNUSED, XErrorEvent *event ATTR_UNUSED)
 
48
{
 
49
    debug("ignoring error\n");
 
50
    return False;
 
51
}
 
52
 
 
53
/*
 
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.
 
57
 */
 
58
 
 
59
static void
 
60
killWindows(Window window)
 
61
{
 
62
    Window root, parent, *children;
 
63
    unsigned int child, nchildren = 0;
 
64
 
 
65
    while (XQueryTree(dpy, window, &root, &parent, &children, &nchildren) &&
 
66
           nchildren > 0) {
 
67
        for (child = 0; child < nchildren; child++) {
 
68
            debug("XKillClient %p\n", children[child]);
 
69
            XKillClient(dpy, children[child]);
 
70
        }
 
71
        XFree(children);
 
72
    }
 
73
}
 
74
 
 
75
static Jmp_buf resetJmp;
 
76
 
 
77
/* ARGSUSED */
 
78
static void
 
79
abortReset(int n ATTR_UNUSED)
 
80
{
 
81
    Longjmp(resetJmp, 1);
 
82
}
 
83
 
 
84
/*
 
85
 * this display connection better not have any windows...
 
86
 */
 
87
 
 
88
void
 
89
pseudoReset()
 
90
{
 
91
    int screen;
 
92
 
 
93
    if (Setjmp(resetJmp)) {
 
94
        logError("pseudoReset timeout\n");
 
95
    } else {
 
96
        (void)Signal(SIGALRM, abortReset);
 
97
        (void)alarm(30);
 
98
        XSetErrorHandler(ignoreErrors);
 
99
        for (screen = 0; screen < ScreenCount(dpy); screen++) {
 
100
            debug("pseudoReset screen %d\n", screen);
 
101
            killWindows(RootWindow(dpy, screen));
 
102
        }
 
103
        debug("before XSync\n");
 
104
        XSync(dpy, False);
 
105
        (void)alarm(0);
 
106
    }
 
107
    Signal(SIGALRM, SIG_DFL);
 
108
    XSetErrorHandler((XErrorHandler)0);
 
109
    debug("pseudoReset done\n");
 
110
}