dtfile: Add missing prototypes
[oweals/cde.git] / cde / programs / dtwm / WmSignal.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 librararies 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 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC. 
25  * ALL RIGHTS RESERVED 
26 */ 
27 /* 
28  * Motif Release 1.2
29 */ 
30 #ifdef REV_INFO
31 #ifndef lint
32 static char rcsid[] = "$XConsortium: WmSignal.c /main/6 1996/10/17 16:20:07 drk $"
33 #endif
34 #endif
35 /*
36  * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
37
38 /*
39  * Included Files:
40  */
41
42 #include "WmGlobal.h" /* This should be the first include */
43 #include <signal.h>
44 #include <unistd.h>
45
46
47 /*
48  * include extern functions
49  */
50
51 #include "WmFeedback.h"
52 #include "WmFunction.h"
53
54
55 /*
56  * Function Declarations:
57  */
58
59 #include "WmSignal.h" 
60
61
62 /*
63  * Global Variables:
64  */
65
66
67 #ifdef WSM
68 \f
69 /*************************************<->*************************************
70  *
71  *  AbortWmSignalHandler ()
72  *
73  *
74  *  Description:
75  *  -----------
76  *  This function is called on receipt of a fatal signal. We reset
77  *  the keyboard focus to pointer root before aborting.
78  *
79  *************************************<->***********************************/
80 static void
81 AbortWmSignalHandler (int sig)
82 {
83     struct sigaction sa;
84
85     /*
86      * Set input focus back to pointer root
87      */
88     XSetInputFocus(DISPLAY, PointerRoot, RevertToPointerRoot, CurrentTime);
89     XSync (DISPLAY, False);
90     XCloseDisplay (DISPLAY);
91
92     /*
93      * Invoke the default handler
94      */
95     (void) sigemptyset(&sa.sa_mask);
96     sa.sa_flags = 0;
97     sa.sa_handler = SIG_DFL;
98     (void) sigaction (sig, &sa, (struct sigaction *) 0);
99
100     kill (getpid(), sig);
101
102 } /* END OF FUNCTION AbortSignalHandler */
103
104 \f
105 /*************************************<->*************************************
106  *
107  *  RestoreDefaultSignalHandlers ()
108  *
109  *
110  *  Description:
111  *  -----------
112  *  This function sets up the signal handlers for the window manager.
113  *
114  *************************************<->***********************************/
115
116 void
117 RestoreDefaultSignalHandlers (void)
118 {
119     struct sigaction sa;
120     struct sigaction osa;
121
122     /*
123      * Restore default action for signals we're interested in.
124      */
125
126     (void) sigemptyset(&sa.sa_mask);
127     sa.sa_flags = 0;
128     sa.sa_handler = SIG_DFL;
129
130     if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
131         (osa.sa_handler != SIG_IGN))
132     {
133         (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
134     }
135
136     if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
137         (osa.sa_handler != SIG_IGN))
138     {
139         (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
140     }
141
142     (void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
143     (void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
144     (void) sigaction (SIGPIPE, &sa, (struct sigaction *) 0);
145     (void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
146     (void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
147     (void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
148     (void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
149     (void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
150 #ifdef SIGSYS
151     (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
152 #endif
153 }
154 #endif /* WSM */
155
156 \f
157 /*************************************<->*************************************
158  *
159  *  SetupWmSignalHandlers ()
160  *
161  *
162  *  Description:
163  *  -----------
164  *  This function sets up the signal handlers for the window manager.
165  *
166  *************************************<->***********************************/
167
168 void SetupWmSignalHandlers (int dummy)
169 {
170 #ifndef WSM
171     void (*signalHandler) ();
172 #endif
173
174 #ifdef WSM
175     struct sigaction    sa;
176     struct sigaction    osa;
177
178     /*
179      * Catch software signals that we ask the user about
180      * before quitting.
181      */
182     (void) sigemptyset(&sa.sa_mask);
183     sa.sa_flags = 0;
184     sa.sa_handler = QuitWmSignalHandler;
185
186     if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
187         (osa.sa_handler != SIG_IGN))
188     {
189         (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
190     }
191
192     if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
193         (osa.sa_handler != SIG_IGN))
194     {
195         (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
196     }
197
198     (void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
199     (void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
200
201     /*
202      * Ignore child death
203      */
204
205 #ifdef SA_NOCLDWAIT
206     sa.sa_flags = SA_NOCLDWAIT;  /* Don't create zombies */
207 #else
208     sa.sa_flags = 0;
209 #endif
210     sa.sa_handler = SIG_IGN;
211     (void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
212     sa.sa_flags = 0;
213
214     /* 
215      * Catch other fatal signals so we can reset the 
216      * keyboard focus to pointer root before aborting
217      */
218     sa.sa_handler = AbortWmSignalHandler;
219
220     (void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
221     (void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
222     (void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
223     (void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
224 #ifdef SIGSYS
225     (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
226 #endif
227
228 #else /* not WSM - original mwm code*/
229
230     signalHandler = (void (*)())signal (SIGINT, SIG_IGN);
231     if (signalHandler != (void (*)())SIG_IGN)
232     {
233         signal (SIGINT, QuitWmSignalHandler);
234     }
235
236     signalHandler = (void (*)())signal (SIGHUP, SIG_IGN);
237     if (signalHandler != (void (*)())SIG_IGN)
238     {
239         signal (SIGHUP, QuitWmSignalHandler);
240     }
241
242     signal (SIGQUIT, QuitWmSignalHandler);
243
244     signal (SIGTERM, QuitWmSignalHandler);
245 #endif /* WSM */
246
247
248 } /* END OF FUNCTION SetupWmSignalHandlers */
249
250 \f
251 /*************************************<->*************************************
252  *
253  *  QuitWmSignalHandler ()
254  *
255  *
256  *  Description:
257  *  -----------
258  *  This function is called on receipt of a signal that is to terminate the
259  *  window manager.
260  *
261  *************************************<->***********************************/
262
263 void QuitWmSignalHandler (int dummy)
264 {
265     if (wmGD.showFeedback & WM_SHOW_FB_KILL)
266     {
267         ConfirmAction (ACTIVE_PSD, QUIT_MWM_ACTION);
268         XFlush(DISPLAY);
269     }
270     else
271     {
272         Do_Quit_Mwm(False);
273     }
274
275 } /* END OF FUNCTION QuitWmSignalHandler */