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