1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
*
* Copyright (c) International Business Machines Corp., 2001
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: faulthdlr.c
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <fullengine.h>
#include "faulthdlr.h"
#include "engine.h"
typedef void (*sighandler_t)(int);
static sighandler_t original_signal_handler[NSIG];
/*
* Simple signal handler that logs the type of signal into the Engine log and
* then unregisters the signal handler for that signal and passes the signal on
* to the previously installed signal handler.
*/
static void signal_handler(int sig_no) {
LOG_CRITICAL("***\n");
LOG_CRITICAL("*** %s\n", sys_siglist[sig_no]);
LOG_CRITICAL("***\n");
if (original_signal_handler[sig_no] != SIG_ERR) {
/* Reset the signal handler to its previous function. */
signal (sig_no, original_signal_handler[sig_no]);
} else {
/*
* We don't have an original handler, which shouldn't happen.
* Set the signal handler to the default handler.
*/
signal (sig_no, SIG_DFL);
}
original_signal_handler[sig_no] = SIG_ERR;
/* Pass the signal on to the next signal handler. */
raise(sig_no);
}
int install_signal_handlers(void) {
int rc = 0;
int i;
LOG_PROC_ENTRY();
/* Initialize the array of original signal handlers. */
for (i = 0; i < NSIG; i++) {
original_signal_handler[i] = SIG_ERR;
}
/* Register for all the signals that can kill a process. */
original_signal_handler[SIGINT] = signal(SIGINT, signal_handler);
original_signal_handler[SIGQUIT] = signal(SIGQUIT, signal_handler);
original_signal_handler[SIGILL] = signal(SIGILL, signal_handler);
original_signal_handler[SIGABRT] = signal(SIGABRT, signal_handler);
original_signal_handler[SIGBUS] = signal(SIGBUS, signal_handler);
original_signal_handler[SIGFPE] = signal(SIGFPE, signal_handler);
original_signal_handler[SIGSEGV] = signal(SIGSEGV, signal_handler);
original_signal_handler[SIGTERM] = signal(SIGTERM, signal_handler);
#ifdef SIGSTKFLT
original_signal_handler[SIGSTKFLT] = signal(SIGSTKFLT, signal_handler);
#endif
original_signal_handler[SIGXCPU] = signal(SIGXCPU, signal_handler);
original_signal_handler[SIGXFSZ] = signal(SIGXFSZ, signal_handler);
original_signal_handler[SIGVTALRM] = signal(SIGVTALRM, signal_handler);
LOG_PROC_EXIT_INT(rc);
return rc;
}
void remove_signal_handlers(void) {
int i;
LOG_PROC_ENTRY();
for (i = 1; i < NSIG; i++) {
if (original_signal_handler[i] != SIG_ERR) {
signal(i, original_signal_handler[i]);
original_signal_handler[i] = SIG_ERR;
}
}
LOG_PROC_EXIT_VOID();
}
|