cdesktopenv/cde/programs/dtwm/WmSignal.c

244 lines
6.1 KiB
C
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* CDE - Common Desktop Environment
*
* Copyright (c) 1993-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these libraries and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
/*
* (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC.
* ALL RIGHTS RESERVED
*/
/*
* Motif Release 1.2
*/
/*
* (c) Copyright 1987, 1988, 1989, 1990 HEWLETT-PACKARD COMPANY */
/*
* Included Files:
*/
#include "WmGlobal.h" /* This should be the first include */
#include <signal.h>
#include <unistd.h>
/*
* include extern functions
*/
#include "WmFeedback.h"
#include "WmFunction.h"
/*
* Function Declarations:
*/
#include "WmSignal.h"
/*
* Global Variables:
*/
/*************************************<->*************************************
*
* AbortWmSignalHandler ()
*
*
* Description:
* -----------
* This function is called on receipt of a fatal signal. We reset
* the keyboard focus to pointer root before aborting.
*
*************************************<->***********************************/
static void
AbortWmSignalHandler (int sig)
{
struct sigaction sa;
/*
* Set input focus back to pointer root
*/
XSetInputFocus(DISPLAY, PointerRoot, RevertToPointerRoot, CurrentTime);
XSync (DISPLAY, False);
XCloseDisplay (DISPLAY);
/*
* Invoke the default handler
*/
(void) sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
(void) sigaction (sig, &sa, (struct sigaction *) 0);
kill (getpid(), sig);
} /* END OF FUNCTION AbortSignalHandler */
/*************************************<->*************************************
*
* RestoreDefaultSignalHandlers ()
*
*
* Description:
* -----------
* This function sets up the signal handlers for the window manager.
*
*************************************<->***********************************/
void
RestoreDefaultSignalHandlers (void)
{
struct sigaction sa;
struct sigaction osa;
/*
* Restore default action for signals we're interested in.
*/
(void) sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
(osa.sa_handler != SIG_IGN))
{
(void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
}
if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
(osa.sa_handler != SIG_IGN))
{
(void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
}
(void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
(void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
(void) sigaction (SIGPIPE, &sa, (struct sigaction *) 0);
(void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
(void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
(void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
(void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
(void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
#ifdef SIGSYS
(void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
#endif
}
/*************************************<->*************************************
*
* SetupWmSignalHandlers ()
*
*
* Description:
* -----------
* This function sets up the signal handlers for the window manager.
*
*************************************<->***********************************/
void SetupWmSignalHandlers (int dummy)
{
struct sigaction sa;
struct sigaction osa;
/*
* Catch software signals that we ask the user about
* before quitting.
*/
(void) sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = QuitWmSignalHandler;
if ((sigaction (SIGINT, (struct sigaction *) 0, &osa) != 0) ||
(osa.sa_handler != SIG_IGN))
{
(void) sigaction (SIGINT, &sa, (struct sigaction *) 0);
}
if ((sigaction (SIGHUP, (struct sigaction *) 0, &osa) != 0) ||
(osa.sa_handler != SIG_IGN))
{
(void) sigaction (SIGHUP, &sa, (struct sigaction *) 0);
}
(void) sigaction (SIGQUIT, &sa, (struct sigaction *) 0);
(void) sigaction (SIGTERM, &sa, (struct sigaction *) 0);
/*
* Ignore child death
*/
#ifdef SA_NOCLDWAIT
sa.sa_flags = SA_NOCLDWAIT; /* Don't create zombies */
#else
sa.sa_flags = 0;
#endif
sa.sa_handler = SIG_IGN;
(void) sigaction (SIGCHLD, &sa, (struct sigaction *) 0);
sa.sa_flags = 0;
/*
* Catch other fatal signals so we can reset the
* keyboard focus to pointer root before aborting
*/
sa.sa_handler = AbortWmSignalHandler;
(void) sigaction (SIGILL, &sa, (struct sigaction *) 0);
(void) sigaction (SIGFPE, &sa, (struct sigaction *) 0);
(void) sigaction (SIGBUS, &sa, (struct sigaction *) 0);
(void) sigaction (SIGSEGV, &sa, (struct sigaction *) 0);
#ifdef SIGSYS
(void) sigaction (SIGSYS, &sa, (struct sigaction *) 0);
#endif
} /* END OF FUNCTION SetupWmSignalHandlers */
/*************************************<->*************************************
*
* QuitWmSignalHandler ()
*
*
* Description:
* -----------
* This function is called on receipt of a signal that is to terminate the
* window manager.
*
*************************************<->***********************************/
void QuitWmSignalHandler (int dummy)
{
if (wmGD.showFeedback & WM_SHOW_FB_KILL)
{
ConfirmAction (ACTIVE_PSD, QUIT_MWM_ACTION);
XFlush(DISPLAY);
}
else
{
Do_Quit_Mwm(False);
}
} /* END OF FUNCTION QuitWmSignalHandler */