2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC.
32 static char rcsid[] = "$XConsortium: WmSignal.c /main/6 1996/10/17 16:20:07 drk $"
36 * (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
42 #include "WmGlobal.h" /* This should be the first include */
48 * include extern functions
51 #include "WmFeedback.h"
52 #include "WmFunction.h"
56 * Function Declarations:
69 /*************************************<->*************************************
71 * AbortWmSignalHandler ()
76 * This function is called on receipt of a fatal signal. We reset
77 * the keyboard focus to pointer root before aborting.
79 *************************************<->***********************************/
81 AbortWmSignalHandler (int sig)
86 * Set input focus back to pointer root
88 XSetInputFocus(DISPLAY, PointerRoot, RevertToPointerRoot, CurrentTime);
89 XSync (DISPLAY, False);
90 XCloseDisplay (DISPLAY);
93 * Invoke the default handler
95 (void) sigemptyset(&sa.sa_mask);
97 sa.sa_handler = SIG_DFL;
98 (void) sigaction (sig, &sa, (struct sigaction *) 0);
100 kill (getpid(), sig);
102 } /* END OF FUNCTION AbortSignalHandler */
105 /*************************************<->*************************************
107 * RestoreDefaultSignalHandlers ()
112 * This function sets up the signal handlers for the window manager.
114 *************************************<->***********************************/
117 RestoreDefaultSignalHandlers (void)
120 struct sigaction osa;
123 * Restore default action for signals we're interested in.
126 (void) sigemptyset(&sa.sa_mask);
128 sa.sa_handler = SIG_DFL;
130 if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
131 (osa.sa_handler != SIG_IGN))
133 (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
136 if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
137 (osa.sa_handler != SIG_IGN))
139 (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
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);
151 (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
157 /*************************************<->*************************************
159 * SetupWmSignalHandlers ()
164 * This function sets up the signal handlers for the window manager.
166 *************************************<->***********************************/
168 void SetupWmSignalHandlers (int dummy)
171 void (*signalHandler) ();
176 struct sigaction osa;
179 * Catch software signals that we ask the user about
182 (void) sigemptyset(&sa.sa_mask);
184 sa.sa_handler = QuitWmSignalHandler;
186 if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
187 (osa.sa_handler != SIG_IGN))
189 (void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
192 if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
193 (osa.sa_handler != SIG_IGN))
195 (void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
198 (void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
199 (void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
206 sa.sa_flags = SA_NOCLDWAIT; /* Don't create zombies */
210 sa.sa_handler = SIG_IGN;
211 (void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
215 * Catch other fatal signals so we can reset the
216 * keyboard focus to pointer root before aborting
218 sa.sa_handler = AbortWmSignalHandler;
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);
225 (void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
228 #else /* not WSM - original mwm code*/
230 signalHandler = (void (*)())signal (SIGINT, SIG_IGN);
231 if (signalHandler != (void (*)())SIG_IGN)
233 signal (SIGINT, QuitWmSignalHandler);
236 signalHandler = (void (*)())signal (SIGHUP, SIG_IGN);
237 if (signalHandler != (void (*)())SIG_IGN)
239 signal (SIGHUP, QuitWmSignalHandler);
242 signal (SIGQUIT, QuitWmSignalHandler);
244 signal (SIGTERM, QuitWmSignalHandler);
248 } /* END OF FUNCTION SetupWmSignalHandlers */
251 /*************************************<->*************************************
253 * QuitWmSignalHandler ()
258 * This function is called on receipt of a signal that is to terminate the
261 *************************************<->***********************************/
263 void QuitWmSignalHandler (int dummy)
265 if (wmGD.showFeedback & WM_SHOW_FB_KILL)
267 ConfirmAction (ACTIVE_PSD, QUIT_MWM_ACTION);
275 } /* END OF FUNCTION QuitWmSignalHandler */