00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030 #include <stdio.h>
00031 #include <signal.h>
00032
00033 #include "sig.h"
00034 #include "dbug_mem.h"
00035
00036
00037
00038 sb_signal_handler_t sb_signal_handler[MAX_SIGNALS];
00039
00040
00041
00042 int
00043 sb_signal_init(void)
00044 {
00045 int i=0;
00046
00047 for (i=0; i<MAX_SIGNALS; i++) {
00048 sb_signal_handler[i] = SIG_DFL;
00049 }
00050
00051 return 0;
00052 }
00053
00054
00055
00056 int
00057 sb_signal_is_initialized(void)
00058 {
00059 static int initialized = 0;
00060
00061 if (initialized == 0) {
00062 if (sb_signal_init() == 0) {
00063 initialized = 1;
00064 }
00065 }
00066
00067 return initialized;
00068 }
00069
00070
00071
00072 int
00073 sb_signal_set_handler(int signum, sb_signal_handler_t handler)
00074 {
00075 sb_signal_handler_t old_handler = SIG_DFL;
00076
00077 if (sb_signal_is_initialized() == 0) {
00078 return -1;
00079 }
00080
00081 if (sb_signal_handler[signum] == SIG_DFL) {
00082 old_handler = signal(signum, handler);
00083 if (old_handler != SIG_ERR) {
00084 sb_signal_handler[signum] = old_handler;
00085 return 0;
00086 }
00087 }
00088
00089 return -1;
00090 }
00091
00092
00093
00094 int
00095 sb_signal_restore_handler(int signum)
00096 {
00097 if (sb_signal_is_initialized() == 0) {
00098 return -1;
00099 }
00100
00101 if (sb_signal_handler[signum] != SIG_DFL) {
00102 if (signal(signum, sb_signal_handler[signum]) == SIG_ERR) {
00103 return -1;
00104 }
00105 }
00106
00107 return 0;
00108 }
00109
00110
00111
00112 int
00113 sb_signal_restore_all_handlers(void)
00114 {
00115 int signum=0;
00116 int error=0;
00117
00118 if (sb_signal_is_initialized() == 0) {
00119 return -1;
00120 }
00121
00122 for (signum=0; signum<MAX_SIGNALS; signum++) {
00123 if (sb_signal_restore_handler(signum) != 0) {
00124 error++;
00125 }
00126 }
00127
00128 if (error > 0) {
00129 return -1;
00130 }
00131
00132 return 0;
00133 }