Gathered signal stuff in handlers.c.

SVN revision: 7338
This commit is contained in:
Kim Woelders 2003-08-18 21:54:27 +00:00
parent 112b31372e
commit fa8b1ab4bb
6 changed files with 149 additions and 317 deletions

20
src/E.h
View File

@ -32,7 +32,6 @@
#include <X11/Xlocale.h>
#include <X11/cursorfont.h>
#include <X11/extensions/shape.h>
/*#include <X11/extensions/XTest.h> */
#include <X11/extensions/XShm.h>
#include <Imlib.h>
#if USE_FNLIB
@ -1834,28 +1833,15 @@ void SetupFallbackClasses(void);
void SetupInit(void);
void MapUnmap(int start);
void SetupSignals(void);
void SetupX(void);
void SetupDirs(void);
void SetupEnv(void);
Window MakeExtInitWin(void);
void SetupUserInitialization(void);
void HandleSigHup(int num);
void HandleSigInt(int num);
void HandleSigQuit(int num);
void HandleSigIll(int num);
void HandleSigAbrt(int num);
void HandleSigFpe(int num);
void HandleSigSegv(int num);
void HandleSigPipe(int num);
void HandleSigAlrm(int num);
void HandleSigTerm(int num);
void HandleSigUsr1(int num);
void HandleSigUsr2(int num);
void HandleSigChild(int num);
void HandleSigTstp(int num);
void HandleSigBus(int num);
/* handlers.c functions */
void SignalsSetup(void);
void SignalsRestore(void);
void EHandleXError(Display * d, XErrorEvent * ev);
void HandleXIOError(Display * d);

View File

@ -22,184 +22,158 @@
*/
#include "E.h"
void
HandleSigHup(int num)
{
EDBUG(7, "HandleSigHup");
num = 0;
doExit("restart");
EDBUG_RETURN_;
}
void
HandleSigInt(int num)
{
EDBUG(7, "HandleSigQuit");
num = 0;
doExit("error");
EDBUG_RETURN_;
}
void
HandleSigQuit(int num)
{
EDBUG(7, "HandleSigQuit");
num = 0;
doExit("error");
EDBUG_RETURN_;
}
void
HandleSigIll(int num)
{
EDBUG(7, "HandleSigIll");
num = 0;
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment performed an Illegal Instruction.\n" "\n"
"This most likely is due to you having installed an run a\n"
"binary of Enlightenment that was compiled for a make or model\n"
"of CPU not 100%% identical or compatible with yours. Please\n"
"either obtain the correct package for your system, or\n"
"re-compile Enlightenment and possibly any support libraries\n"
"that you got in binary format to run Enlightenment.\n"));
doExit("error");
EDBUG_RETURN_;
}
void
HandleSigAbrt(int num)
{
EDBUG(7, "HandleSigAbrt");
num = 0;
doExit("error");
EDBUG_RETURN_;
}
void
HandleSigFpe(int num)
{
EDBUG(7, "HandleSigFpe");
num = 0;
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment caused a Floating Point Exception.\n" "\n"
"This means that Enlightenment or support library routines it calls\n"
"have performed an illegal mathematical operation (most likely\n"
"dividing a number by zero). This is most likely a bug. It is\n"
"recommended to restart now. If you wish to help fix this please\n"
"compile Enlightenment with debugging symbols in and run\n"
"Enlightenment under gdb so you can backtrace for where it died and\n"
"send in a useful bug report with backtrace information and variable\n"
"dumps etc.\n"));
doExit("error");
EDBUG_RETURN_;
}
void
HandleSigSegv(int num)
static void
SignalHandler(int sig)
{
static int loop_count = 0;
EDBUG(7, "HandleSigSegv");
if (loop_count > 0)
abort();
loop_count++;
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment caused Segment Violation (Segfault)\n" "\n"
"This means that Enlightenment or support library routines it calls\n"
"have accessed areas of your system's memory that they are not\n"
"allowed access to. This is most likely a bug. It is recommended to\n"
"restart now. If you wish to help fix this please compile\n"
"Enlightenment with debugging symbols in and run Enlightenment\n"
"under gdb so you can backtrace for where it died and send in a\n"
"useful bug report with backtrace information and variable\n"
"dumps etc.\n"));
abort();
num = 0;
EDBUG_RETURN_;
}
void
HandleSigPipe(int num)
{
EDBUG(7, "HandleSigPipe");
num = 0;
EDBUG_RETURN_;
}
void
HandleSigAlrm(int num)
{
EDBUG(7, "HandleSigAlrm");
num = 0;
EDBUG_RETURN_;
}
void
HandleSigTerm(int num)
{
EDBUG(7, "HandleSigTerm");
num = 0;
doExit("error");
EDBUG_RETURN_;
}
void
HandleSigUsr1(int num)
{
EDBUG(7, "HandleSigUsr1");
num = 0;
EDBUG_RETURN_;
}
void
HandleSigUsr2(int num)
{
EDBUG(7, "HandleSigUsr2");
num = 0;
EDBUG_RETURN_;
}
void
HandleSigChild(int num)
{
int status;
EDBUG(7, "HandleSigChild");
num = 0;
EDBUG(7, "SignalHandler");
switch (sig)
{
case SIGHUP:
doExit("restart");
break;
default:
case SIGINT:
case SIGQUIT:
case SIGABRT:
case SIGTERM:
doExit("error");
break;
case SIGPIPE:
case SIGALRM:
case SIGUSR1:
case SIGUSR2:
break;
case SIGILL:
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment performed an Illegal Instruction.\n" "\n"
"This most likely is due to you having installed an run a\n"
"binary of Enlightenment that was compiled for a make or model\n"
"of CPU not 100%% identical or compatible with yours. Please\n"
"either obtain the correct package for your system, or\n"
"re-compile Enlightenment and possibly any support libraries\n"
"that you got in binary format to run Enlightenment.\n"));
doExit("error");
break;
case SIGFPE:
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment caused a Floating Point Exception.\n" "\n"
"This means that Enlightenment or support library routines it calls\n"
"have performed an illegal mathematical operation (most likely\n"
"dividing a number by zero). This is most likely a bug. It is\n"
"recommended to restart now. If you wish to help fix this please\n"
"compile Enlightenment with debugging symbols in and run\n"
"Enlightenment under gdb so you can backtrace for where it died and\n"
"send in a useful bug report with backtrace information and variable\n"
"dumps etc.\n"));
doExit("error");
break;
case SIGSEGV:
if (loop_count > 0)
abort();
loop_count++;
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment caused Segment Violation (Segfault)\n" "\n"
"This means that Enlightenment or support library routines it calls\n"
"have accessed areas of your system's memory that they are not\n"
"allowed access to. This is most likely a bug. It is recommended to\n"
"restart now. If you wish to help fix this please compile\n"
"Enlightenment with debugging symbols in and run Enlightenment\n"
"under gdb so you can backtrace for where it died and send in a\n"
"useful bug report with backtrace information and variable\n"
"dumps etc.\n"));
abort();
break;
case SIGBUS:
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment caused Bus Error.\n" "\n"
"It is suggested you check your hardware and OS installation.\n"
"It is highly unusual to cause Bus Errors on operational\n"
"hardware.\n"));
break;
case SIGCHLD:
#ifndef __EMX__
while (waitpid(-1, &status, WNOHANG) > 0);
while (waitpid(-1, &status, WNOHANG) > 0);
#else
waitpid(-1, &status, WNOHANG);
waitpid(-1, &status, WNOHANG);
#endif
break;
}
EDBUG_RETURN_;
}
void
HandleSigTstp(int num)
SignalsSetup(void)
{
EDBUG(7, "HandleSigTstp");
num = 0;
/* This function will set up all the signal handlers for E */
static const int signals[] = {
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGPIPE,
SIGALRM, SIGTERM, SIGUSR1, SIGUSR2, SIGCHLD, SIGBUS
};
int i;
struct sigaction sa;
EDBUG(6, "SignalsSetup");
for (i = 0; i < sizeof(signals) / sizeof(int); i++)
{
sa.sa_handler = SignalHandler;
#ifndef __EMX__
sa.sa_flags = (signals[i] == SIGCHLD) ? SA_RESTART : 0;
#else
sa.sa_flags = 0;
#endif
sigemptyset(&sa.sa_mask);
sigaction(signals[i], &sa, (struct sigaction *)0);
}
EDBUG_RETURN_;
}
void
HandleSigBus(int num)
SignalsRestore(void)
{
EDBUG(7, "HandleSigBus");
num = 0;
if (disp)
UngrabX();
DialogAlert(_
("Enlightenment caused Bus Error.\n" "\n"
"It is suggested you check your hardware and OS installation.\n"
"It is highly unusual to cause Bus Errors on operational\n"
"hardware.\n"));
/* This function will restore all the signal handlers for E */
EDBUG(6, "SignalsRestore");
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGABRT, SIG_DFL);
signal(SIGFPE, SIG_IGN);
signal(SIGSEGV, SIG_IGN);
signal(SIGPIPE, SIG_DFL);
signal(SIGALRM, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
#ifdef SIGTSTP
signal(SIGTSTP, SIG_DFL);
#endif
signal(SIGBUS, SIG_IGN);
EDBUG_RETURN_;
}

View File

@ -228,7 +228,7 @@ main(int argc, char **argv)
SetSMUserThemePath(themepath);
/* run most of the setup */
SetupSignals();
SignalsSetup();
SetupX();
BlumFlimFrub();
ZoomInit();

View File

@ -190,25 +190,11 @@ EExit(void *code)
XSelectInput(disp, root.win, 0);
XCloseDisplay(disp);
}
XSetErrorHandler((XErrorHandler) NULL);
XSetIOErrorHandler((XIOErrorHandler) NULL);
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGABRT, SIG_DFL);
signal(SIGFPE, SIG_IGN);
signal(SIGSEGV, SIG_IGN);
signal(SIGPIPE, SIG_DFL);
signal(SIGALRM, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
#ifdef SIGTSTP
signal(SIGTSTP, SIG_DFL);
#endif
signal(SIGBUS, SIG_IGN);
SignalsRestore();
if (master_pid == getpid())
{

View File

@ -215,25 +215,12 @@ SC_Init(void)
XFree(retval);
return;
}
XSetErrorHandler((XErrorHandler) NULL);
XSetIOErrorHandler((XIOErrorHandler) NULL);
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGABRT, SIG_DFL);
signal(SIGFPE, SIG_IGN);
signal(SIGSEGV, SIG_IGN);
signal(SIGPIPE, SIG_DFL);
signal(SIGALRM, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
#ifdef SIGTSTP
signal(SIGTSTP, SIG_DFL);
#endif
signal(SIGBUS, SIG_IGN);
SignalsRestore();
sc_disp = XOpenDisplay(DisplayString(disp));
XGrabServer(sc_disp);
#ifdef HAVE_LIBXTST

View File

@ -109,93 +109,6 @@ MapUnmap(int start)
EDBUG_RETURN_;
}
void
SetupSignals()
{
/* This function will set up all the signal handlers for E */
struct sigaction sa;
EDBUG(6, "SetupSignals");
sa.sa_handler = HandleSigHup;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGHUP, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigInt;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGINT, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigQuit;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGQUIT, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigIll;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGILL, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigAbrt;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGABRT, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigFpe;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGFPE, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigSegv;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigPipe;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGPIPE, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigAlrm;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGALRM, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigTerm;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGTERM, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigUsr1;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGUSR1, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigUsr2;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGUSR2, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigChild;
#ifndef __EMX__
sa.sa_flags = SA_RESTART;
#else
sa.sa_flags = 0;
#endif
sigemptyset(&sa.sa_mask);
sigaction(SIGCHLD, &sa, (struct sigaction *)0);
sa.sa_handler = HandleSigBus;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
sigaction(SIGBUS, &sa, (struct sigaction *)0);
EDBUG_RETURN_;
}
void
SetupX()
{
@ -777,26 +690,12 @@ MakeExtInitWin(void)
return win;
}
/* on solairs connection stays up - close */
XSetErrorHandler((XErrorHandler) NULL);
XSetIOErrorHandler((XIOErrorHandler) NULL);
signal(SIGHUP, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGABRT, SIG_DFL);
signal(SIGFPE, SIG_IGN);
signal(SIGSEGV, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
signal(SIGALRM, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGUSR1, SIG_DFL);
signal(SIGUSR2, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
#ifdef SIGTSTP
signal(SIGTSTP, SIG_DFL);
#endif
signal(SIGBUS, SIG_IGN);
SignalsRestore();
d2 = XOpenDisplay(DisplayString(disp));
close(ConnectionNumber(disp));