appmanager action files: create and populate them
[oweals/cde.git] / cde / programs / dtlogin / reset.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*                                                                      *
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.                                *
28  */
29 /*
30  * xdm - display manager daemon
31  *
32  * $XConsortium: reset.c /main/4 1995/10/27 16:14:40 rswiston $
33  *
34  * Copyright 1988 Massachusetts Institute of Technology
35  *
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.
45  *
46  * Author:  Keith Packard, MIT X Consortium
47  */
48
49 /*
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.
53  */
54
55 # include       <setjmp.h>
56 # include       <sys/types.h>
57 # include       <sys/signal.h>
58 # include       "dm.h"
59 # include       "vgmsg.h"
60
61
62 /***************************************************************************
63  *
64  *  Local procedure declarations
65  *
66  ***************************************************************************/
67
68 static SIGVAL abortReset( int arg ) ;
69 static int ignoreErrors( Display *dpy, XErrorEvent *event) ;
70 static void killWindows( Display *dpy, Window window) ;
71
72
73
74 /***************************************************************************
75  *
76  *  
77  *
78  ***************************************************************************/
79
80 /*ARGSUSED*/
81 static int 
82 ignoreErrors( Display *dpy, XErrorEvent *event )
83 {
84         Debug ("Ignoring error...\n");
85         return 1;
86 }
87
88 /*
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.
92  */
93
94 static void 
95 killWindows( Display *dpy, Window window )
96 {
97         Window  root, parent, *children;
98         int     child;
99         unsigned int nchildren = 0;
100         
101         while (XQueryTree (dpy, window, &root, &parent, &children, &nchildren)
102                && nchildren > 0)
103         {
104                 for (child = 0; child < nchildren; child++) {
105                         Debug ("Calling XKillClient() for window 0x%x\n",
106                                 children[child]);
107                         XKillClient (dpy, children[child]);
108                 }
109                 XFree ((char *)children);
110         }
111 }
112
113 static jmp_buf  resetJmp;
114
115 static SIGVAL
116 abortReset( int arg )
117 {
118         longjmp (resetJmp, 1);
119 }
120
121 /*
122  * this display connection better not have any windows...
123  */
124  
125 void 
126 pseudoReset( Display *dpy )
127 {
128         Window  root;
129         int     screen;
130
131         if (setjmp (resetJmp)) {
132                 LogError(
133                   ReadCatalog(MC_LOG_SET,MC_LOG_PSEUDO,MC_DEF_LOG_PSEUDO));
134         } else {
135                 signal (SIGALRM, abortReset);
136                 alarm (30);
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);
142                 }
143                 Debug ("Before XSync\n");
144                 XSync (dpy, False);
145                 (void) alarm (0);
146         }
147         signal (SIGALRM, SIG_DFL);
148         XSetErrorHandler ((int (*)()) 0);
149         Debug ("pseudoReset() done\n");
150 }