1
|
1 // sighandlers.cc -*- C++ -*- |
|
2 /* |
|
3 |
529
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
1
|
26 #endif |
|
27 |
834
|
28 #include <sys/types.h> |
|
29 #ifdef HAVE_UNISTD_H |
|
30 #include <unistd.h> |
|
31 #endif |
635
|
32 #include <new.h> |
1
|
33 #include <signal.h> |
|
34 |
|
35 #include "sighandlers.h" |
|
36 #include "octave.h" |
|
37 #include "error.h" |
|
38 #include "utils.h" |
|
39 |
|
40 // Nonzero means we have already printed a message for this series of |
|
41 // SIGPIPES. We assume that the writer will eventually give up. |
|
42 int pipe_handler_error_count = 0; |
|
43 |
|
44 // Nonzero means we can be interrupted. |
|
45 int can_interrupt = 0; |
|
46 |
|
47 static void |
|
48 my_friendly_exit (const char *sig_name, int sig_number) |
|
49 { |
|
50 error ("caught %s -- stopping myself...", sig_name); |
|
51 clean_up_and_exit (sig_number); |
|
52 } |
|
53 |
635
|
54 // I know, not really a signal handler. |
|
55 |
|
56 static void |
|
57 octave_new_handler (void) |
|
58 { |
|
59 error ("new: virtual memory exhausted -- stopping myself"); |
|
60 clean_up_and_exit (1); |
|
61 } |
|
62 |
1
|
63 static RETSIGTYPE |
834
|
64 generic_sig_handler (int i) |
1
|
65 { |
834
|
66 my_friendly_exit (sys_siglist[i], i); |
1
|
67 |
834
|
68 #if RETSIGTYPE == void |
|
69 return; |
|
70 #else |
|
71 return 0; |
|
72 #endif |
1
|
73 } |
|
74 |
635
|
75 // Handle SIGINT by restarting the parser (see octave.cc). |
|
76 |
834
|
77 // XXX FIXME XXX -- it would probably be good to try to use POSIX |
|
78 // signal interface if it is available. |
|
79 |
1
|
80 static RETSIGTYPE |
|
81 sigint_handler (int i) |
|
82 { |
834
|
83 // Can this ever cause trouble on systems that don't forget signal |
|
84 // handlers when they are invoked? |
|
85 |
|
86 signal (SIGINT, sigint_handler); |
|
87 |
1
|
88 if (can_interrupt) |
|
89 { |
|
90 jump_to_top_level (); |
|
91 panic_impossible (); |
|
92 } |
|
93 |
|
94 #if RETSIGTYPE == void |
|
95 return; |
|
96 #else |
|
97 return 0; |
|
98 #endif |
|
99 } |
|
100 |
|
101 static RETSIGTYPE |
|
102 sigpipe_handler (int i) |
|
103 { |
834
|
104 // Can this ever cause trouble on systems that don't forget signal |
|
105 // handlers when they are invoked? |
|
106 |
|
107 signal (SIGPIPE, sigpipe_handler); |
|
108 |
1
|
109 if (pipe_handler_error_count++ == 0) |
529
|
110 message (0, "broken pipe"); |
1
|
111 |
|
112 // Don\'t loop forever on account of this. |
|
113 if (pipe_handler_error_count > 100) |
|
114 jump_to_top_level (); |
|
115 |
|
116 #if RETSIGTYPE == void |
|
117 return; |
|
118 #else |
|
119 return 0; |
|
120 #endif |
|
121 } |
|
122 |
635
|
123 // Install all the handlers for the signals we might care about. |
|
124 |
1
|
125 void |
|
126 install_signal_handlers (void) |
|
127 { |
635
|
128 set_new_handler (octave_new_handler); |
|
129 |
1
|
130 #ifdef SIGABRT |
834
|
131 signal (SIGABRT, generic_sig_handler); |
1
|
132 #endif |
|
133 |
|
134 #ifdef SIGALRM |
834
|
135 signal (SIGALRM, generic_sig_handler); |
1
|
136 #endif |
|
137 |
|
138 #ifdef SIGBUS |
834
|
139 signal (SIGBUS, generic_sig_handler); |
1
|
140 #endif |
|
141 |
|
142 #ifdef SIGEMT |
834
|
143 signal (SIGEMT, generic_sig_handler); |
1
|
144 #endif |
|
145 |
|
146 #ifdef SIGFPE |
834
|
147 signal (SIGFPE, generic_sig_handler); |
1
|
148 #endif |
|
149 |
|
150 #ifdef SIGHUP |
834
|
151 signal (SIGHUP, generic_sig_handler); |
1
|
152 #endif |
|
153 |
|
154 #ifdef SIGILL |
834
|
155 signal (SIGILL, generic_sig_handler); |
1
|
156 #endif |
|
157 |
|
158 #ifdef SIGINT |
|
159 signal (SIGINT, sigint_handler); |
|
160 #endif |
|
161 |
|
162 #ifdef SIGIOT |
834
|
163 signal (SIGIOT, generic_sig_handler); |
1
|
164 #endif |
|
165 |
|
166 #ifdef SIGLOST |
834
|
167 signal (SIGLOST, generic_sig_handler); |
1
|
168 #endif |
|
169 |
|
170 #ifdef SIGPIPE |
|
171 signal (SIGPIPE, sigpipe_handler); |
|
172 #endif |
|
173 |
|
174 #ifdef SIGPOLL |
834
|
175 signal (SIGPOLL, generic_sig_handler); |
1
|
176 #endif |
|
177 |
|
178 #ifdef SIGPROF |
834
|
179 signal (SIGPROF, generic_sig_handler); |
1
|
180 #endif |
|
181 |
|
182 #ifdef SIGQUIT |
834
|
183 signal (SIGQUIT, generic_sig_handler); |
1
|
184 #endif |
|
185 |
|
186 #ifdef SIGSEGV |
834
|
187 signal (SIGSEGV, generic_sig_handler); |
1
|
188 #endif |
|
189 |
|
190 #ifdef SIGSYS |
834
|
191 signal (SIGSYS, generic_sig_handler); |
1
|
192 #endif |
|
193 |
|
194 #ifdef SIGTERM |
834
|
195 signal (SIGTERM, generic_sig_handler); |
1
|
196 #endif |
|
197 |
|
198 #ifdef SIGTRAP |
834
|
199 signal (SIGTRAP, generic_sig_handler); |
1
|
200 #endif |
|
201 |
|
202 #ifdef SIGUSR1 |
834
|
203 signal (SIGUSR1, generic_sig_handler); |
1
|
204 #endif |
|
205 |
|
206 #ifdef SIGUSR2 |
834
|
207 signal (SIGUSR2, generic_sig_handler); |
1
|
208 #endif |
|
209 |
|
210 #ifdef SIGVTALRM |
834
|
211 signal (SIGVTALRM, generic_sig_handler); |
1
|
212 #endif |
|
213 |
|
214 #ifdef SIGXCPU |
834
|
215 signal (SIGXCPU, generic_sig_handler); |
1
|
216 #endif |
|
217 |
|
218 #ifdef SIGXFSZ |
834
|
219 signal (SIGXFSZ, generic_sig_handler); |
1
|
220 #endif |
|
221 } |
|
222 |
|
223 /* |
|
224 ;;; Local Variables: *** |
|
225 ;;; mode: C++ *** |
|
226 ;;; page-delimiter: "^/\\*" *** |
|
227 ;;; End: *** |
|
228 */ |