Mercurial > hg > octave-lyh
annotate src/sighandlers.cc @ 13951:79aa00a94e9e
doc: Document "local" option for configuration variables.
* svd.cc, defaults.cc, dirfns.cc, error.cc, help.cc, input.cc, load-save.cc,
ls-oct-ascii.cc, oct-hist.cc, ov-base.cc, ov-range.cc, ov-struct.cc,
ov-usr-fcn.cc, pager.cc, pr-output.cc, pt-binop.cc, pt-eval.cc, pt-mat.cc,
sighandlers.cc, variables.cc: Document "local" option for configuration
variables.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 27 Nov 2011 16:07:13 -0800 |
parents | 03f125c0fb7b |
children | 7dd7cccf0757 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1993-2011 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
240 | 23 #ifdef HAVE_CONFIG_H |
1230 | 24 #include <config.h> |
1 | 25 #endif |
26 | |
2536 | 27 #include <cstdlib> |
28 | |
3503 | 29 #include <iostream> |
1344 | 30 #include <new> |
31 | |
834 | 32 #include <sys/types.h> |
33 #include <unistd.h> | |
1343 | 34 |
3281 | 35 #include "cmd-edit.h" |
5453 | 36 #include "oct-syscalls.h" |
4153 | 37 #include "quit.h" |
3281 | 38 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
39 #include "debug.h" |
4185 | 40 #include "defun.h" |
1352 | 41 #include "error.h" |
10194 | 42 #include "input.h" |
1373 | 43 #include "load-save.h" |
4294 | 44 #include "oct-map.h" |
2091 | 45 #include "pager.h" |
4185 | 46 #include "pt-bp.h" |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
47 #include "pt-eval.h" |
1 | 48 #include "sighandlers.h" |
4787 | 49 #include "sysdep.h" |
1352 | 50 #include "syswait.h" |
2091 | 51 #include "toplev.h" |
1 | 52 #include "utils.h" |
5794 | 53 #include "variables.h" |
1 | 54 |
55 // Nonzero means we have already printed a message for this series of | |
56 // SIGPIPES. We assume that the writer will eventually give up. | |
57 int pipe_handler_error_count = 0; | |
58 | |
3018 | 59 // TRUE means we can be interrupted. |
60 bool can_interrupt = false; | |
1 | 61 |
4185 | 62 // TRUE means we should try to enter the debugger on SIGINT. |
63 static bool Vdebug_on_interrupt = false; | |
64 | |
4449 | 65 // Allow users to avoid writing octave-core for SIGHUP (sent by |
66 // closing gnome-terminal, for example). Note that this variable has | |
67 // no effect if Vcrash_dumps_octave_core is FALSE. | |
5794 | 68 static bool Vsighup_dumps_octave_core = true; |
4449 | 69 |
70 // Similar to Vsighup_dumps_octave_core, but for SIGTERM signal. | |
5794 | 71 static bool Vsigterm_dumps_octave_core = true; |
4449 | 72 |
5142 | 73 // List of signals we have caught since last call to octave_signal_handler. |
74 static bool octave_signals_caught[NSIG]; | |
75 | |
11525
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
76 // Signal handler return type. |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
77 #ifndef BADSIG |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
78 #define BADSIG (void (*)(int))-1 |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
79 #endif |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
80 |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
81 #define BLOCK_SIGNAL(sig, nvar, ovar) \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
82 do \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
83 { \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
84 gnulib::sigemptyset (&nvar); \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
85 gnulib::sigaddset (&nvar, sig); \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
86 gnulib::sigemptyset (&ovar); \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
87 gnulib::sigprocmask (SIG_BLOCK, &nvar, &ovar); \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
88 } \ |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
89 while (0) |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
90 |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
91 #if !defined (SIGCHLD) && defined (SIGCLD) |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
92 #define SIGCHLD SIGCLD |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
93 #endif |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
94 |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
95 #define BLOCK_CHILD(nvar, ovar) BLOCK_SIGNAL (SIGCHLD, nvar, ovar) |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
96 #define UNBLOCK_CHILD(ovar) gnulib::sigprocmask (SIG_SETMASK, &ovar, 0) |
ab231f944252
avoid exposing gnulib:: in header files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
97 |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
98 // Called from octave_quit () to actually do something about the signals |
5142 | 99 // we have caught. |
100 | |
101 void | |
102 octave_signal_handler (void) | |
103 { | |
104 // The list of signals is relatively short, so we will just go | |
105 // linearly through the list. | |
106 | |
107 for (int i = 0; i < NSIG; i++) | |
108 { | |
109 if (octave_signals_caught[i]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
110 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
111 octave_signals_caught[i] = false; |
5142 | 112 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
113 switch (i) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
114 { |
5451 | 115 #ifdef SIGCHLD |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
116 case SIGCHLD: |
11555
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
117 { |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
118 volatile octave_interrupt_handler saved_interrupt_handler |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
119 = octave_ignore_interrupts (); |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
120 |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
121 sigset_t set, oset; |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
122 |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
123 BLOCK_CHILD (set, oset); |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
124 |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
125 octave_child_list::wait (); |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
126 |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
127 octave_set_interrupt_handler (saved_interrupt_handler); |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
128 |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
129 UNBLOCK_CHILD (oset); |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
130 |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
131 octave_child_list::reap (); |
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
132 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
133 break; |
5451 | 134 #endif |
5142 | 135 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
136 case SIGFPE: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
137 std::cerr << "warning: floating point exception -- trying to return to prompt" << std::endl; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
138 break; |
5142 | 139 |
5451 | 140 #ifdef SIGPIPE |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
141 case SIGPIPE: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
142 std::cerr << "warning: broken pipe -- some output may be lost" << std::endl; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
143 break; |
5451 | 144 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
145 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
146 } |
5142 | 147 } |
148 } | |
149 | |
1 | 150 static void |
4787 | 151 my_friendly_exit (const char *sig_name, int sig_number, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
152 bool save_vars = true) |
1 | 153 { |
2536 | 154 static bool been_there_done_that = false; |
155 | |
156 if (been_there_done_that) | |
157 { | |
2554 | 158 #if defined (SIGABRT) |
2536 | 159 octave_set_signal_handler (SIGABRT, SIG_DFL); |
160 #endif | |
161 | |
3644 | 162 std::cerr << "panic: attempted clean up apparently failed -- aborting...\n"; |
5451 | 163 |
164 MINGW_SIGNAL_CLEANUP (); | |
165 | |
2536 | 166 abort (); |
167 } | |
168 else | |
169 { | |
170 been_there_done_that = true; | |
1373 | 171 |
3644 | 172 std::cerr << "panic: " << sig_name << " -- stopping myself...\n"; |
2536 | 173 |
4787 | 174 if (save_vars) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
175 dump_octave_core (); |
2536 | 176 |
3162 | 177 if (sig_number < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
178 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
179 MINGW_SIGNAL_CLEANUP (); |
5451 | 180 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
181 exit (1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
182 } |
3162 | 183 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
184 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
185 octave_set_signal_handler (sig_number, SIG_DFL); |
3162 | 186 |
4092 | 187 #if defined (HAVE_RAISE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
188 raise (sig_number); |
4092 | 189 #elif defined (HAVE_KILL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
190 kill (getpid (), sig_number); |
4092 | 191 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
192 exit (1); |
4092 | 193 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
194 } |
4092 | 195 |
2536 | 196 } |
1 | 197 } |
198 | |
1446 | 199 sig_handler * |
5770 | 200 octave_set_signal_handler (int sig, sig_handler *handler, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
201 bool restart_syscalls) |
1446 | 202 { |
203 struct sigaction act, oact; | |
5144 | 204 |
1446 | 205 act.sa_handler = handler; |
206 act.sa_flags = 0; | |
5144 | 207 |
10344
65974373505a
Do not use SIGALRM unconditinally.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10315
diff
changeset
|
208 #if defined (SIGALRM) |
5144 | 209 if (sig == SIGALRM) |
210 { | |
211 #if defined (SA_INTERRUPT) | |
212 act.sa_flags |= SA_INTERRUPT; | |
213 #endif | |
214 } | |
10344
65974373505a
Do not use SIGALRM unconditinally.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10315
diff
changeset
|
215 #endif |
5144 | 216 #if defined (SA_RESTART) |
10344
65974373505a
Do not use SIGALRM unconditinally.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10315
diff
changeset
|
217 #if defined (SIGALRM) |
65974373505a
Do not use SIGALRM unconditinally.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10315
diff
changeset
|
218 else |
65974373505a
Do not use SIGALRM unconditinally.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10315
diff
changeset
|
219 #endif |
5775 | 220 // FIXME -- Do we also need to explicitly disable SA_RESTART? |
10344
65974373505a
Do not use SIGALRM unconditinally.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10315
diff
changeset
|
221 if (restart_syscalls) |
5770 | 222 act.sa_flags |= SA_RESTART; |
5144 | 223 #endif |
224 | |
10411 | 225 gnulib::sigemptyset (&act.sa_mask); |
226 gnulib::sigemptyset (&oact.sa_mask); | |
5144 | 227 |
10411 | 228 gnulib::sigaction (sig, &act, &oact); |
5144 | 229 |
1446 | 230 return oact.sa_handler; |
231 } | |
232 | |
10246 | 233 static void |
1446 | 234 generic_sig_handler (int sig) |
1 | 235 { |
5844 | 236 my_friendly_exit (strsignal (sig), sig); |
1 | 237 } |
238 | |
2091 | 239 // Handle SIGCHLD. |
1230 | 240 |
4064 | 241 #ifdef SIGCHLD |
10246 | 242 static void |
2092 | 243 sigchld_handler (int /* sig */) |
1230 | 244 { |
11555
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
245 octave_signal_caught = 1; |
2626 | 246 |
11555
f359cfc6e24d
sighandlers.cc: wait for children in octave_signal_handler, not sigchld_handler
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
247 octave_signals_caught[SIGCHLD] = true; |
1230 | 248 } |
4064 | 249 #endif /* defined(SIGCHLD) */ |
1230 | 250 |
4064 | 251 #ifdef SIGFPE |
1373 | 252 #if defined (__alpha__) |
10246 | 253 static void |
1488 | 254 sigfpe_handler (int /* sig */) |
1373 | 255 { |
5142 | 256 if (can_interrupt && octave_interrupt_state >= 0) |
257 { | |
258 octave_signal_caught = 1; | |
1373 | 259 |
5142 | 260 octave_signals_caught[SIGFPE] = true; |
4182 | 261 |
5142 | 262 octave_interrupt_state++; |
263 } | |
1373 | 264 } |
4064 | 265 #endif /* defined(__alpha__) */ |
266 #endif /* defined(SIGFPE) */ | |
1373 | 267 |
4449 | 268 #if defined (SIGHUP) || defined (SIGTERM) |
10246 | 269 static void |
4449 | 270 sig_hup_or_term_handler (int sig) |
271 { | |
272 switch (sig) | |
273 { | |
274 #if defined (SIGHUP) | |
275 case SIGHUP: | |
276 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
277 if (Vsighup_dumps_octave_core) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
278 dump_octave_core (); |
4449 | 279 } |
280 break; | |
281 #endif | |
282 | |
283 #if defined (SIGTERM) | |
284 case SIGTERM: | |
285 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
286 if (Vsigterm_dumps_octave_core) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
287 dump_octave_core (); |
4449 | 288 } |
289 break; | |
290 #endif | |
291 | |
292 default: | |
293 break; | |
294 } | |
295 | |
296 clean_up_and_exit (0); | |
297 } | |
298 #endif | |
299 | |
3343 | 300 #if 0 |
3281 | 301 #if defined (SIGWINCH) |
10246 | 302 static void |
3281 | 303 sigwinch_handler (int /* sig */) |
304 { | |
305 command_editor::resize_terminal (); | |
306 } | |
307 #endif | |
3343 | 308 #endif |
3281 | 309 |
635 | 310 // Handle SIGINT by restarting the parser (see octave.cc). |
2554 | 311 // |
312 // This also has to work for SIGBREAK (on systems that have it), so we | |
313 // use the value of sig, instead of just assuming that it is called | |
314 // for SIGINT only. | |
635 | 315 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
316 static void |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
317 user_abort (const char *sig_name, int sig_number) |
1 | 318 { |
4172 | 319 if (! octave_initialized) |
320 exit (1); | |
321 | |
1 | 322 if (can_interrupt) |
323 { | |
4185 | 324 if (Vdebug_on_interrupt) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
325 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
326 if (! octave_debug_on_interrupt_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
327 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
328 tree_evaluator::debug_mode = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
329 octave_debug_on_interrupt_state = true; |
4185 | 330 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
331 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
332 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
333 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
334 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
335 // Clear the flag and do normal interrupt stuff. |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
336 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
337 tree_evaluator::debug_mode |
10194 | 338 = bp_table::have_breakpoints () || Vdebugging; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
339 octave_debug_on_interrupt_state = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
340 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
341 } |
4185 | 342 |
4153 | 343 if (octave_interrupt_immediately) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
344 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
345 if (octave_interrupt_state == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
346 octave_interrupt_state = 1; |
7481
78f3811155f7
use exceptions in liboctave error handler
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
347 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
348 octave_jump_to_enclosing_context (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
349 } |
4429 | 350 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
351 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
352 // If we are already cleaning up from a previous interrupt, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
353 // take note of the fact that another interrupt signal has |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
354 // arrived. |
4793 | 355 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
356 if (octave_interrupt_state < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
357 octave_interrupt_state = 0; |
4793 | 358 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
359 octave_signal_caught = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
360 octave_interrupt_state++; |
4787 | 361 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
362 if (interactive && octave_interrupt_state == 2) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
363 std::cerr << "Press Control-C again to abort." << std::endl; |
4787 | 364 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
365 if (octave_interrupt_state >= 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
366 my_friendly_exit (sig_name, sig_number, true); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
367 } |
1 | 368 } |
369 | |
5451 | 370 } |
371 | |
10246 | 372 static void |
5451 | 373 sigint_handler (int sig) |
374 { | |
375 #ifdef USE_W32_SIGINT | |
376 if (w32_in_main_thread ()) | |
5844 | 377 user_abort (strsignal (sig), sig); |
5451 | 378 else |
379 w32_raise (sig); | |
380 #else | |
5844 | 381 user_abort (strsignal (sig), sig); |
5451 | 382 #endif |
1 | 383 } |
384 | |
4064 | 385 #ifdef SIGPIPE |
10246 | 386 static void |
1488 | 387 sigpipe_handler (int /* sig */) |
1 | 388 { |
5142 | 389 octave_signal_caught = 1; |
390 | |
391 octave_signals_caught[SIGPIPE] = true; | |
1 | 392 |
1358 | 393 // Don't loop forever on account of this. |
394 | |
5142 | 395 if (pipe_handler_error_count++ > 100 && octave_interrupt_state >= 0) |
4787 | 396 octave_interrupt_state++; |
1 | 397 } |
4064 | 398 #endif /* defined(SIGPIPE) */ |
1 | 399 |
5451 | 400 #ifdef USE_W32_SIGINT |
401 static BOOL CALLBACK | |
402 w32_sigint_handler (DWORD sig) | |
403 { | |
404 const char *sig_name; | |
405 | |
406 switch(sig) | |
407 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11555
diff
changeset
|
408 case CTRL_BREAK_EVENT: |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11555
diff
changeset
|
409 sig_name = "Ctrl-Break"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
410 break; |
5451 | 411 case CTRL_C_EVENT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
412 sig_name = "Ctrl-C"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
413 break; |
5451 | 414 case CTRL_CLOSE_EVENT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
415 sig_name = "close console"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
416 break; |
5451 | 417 case CTRL_LOGOFF_EVENT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
418 sig_name = "logoff"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
419 break; |
5451 | 420 case CTRL_SHUTDOWN_EVENT: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
421 sig_name = "shutdown"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
422 break; |
5451 | 423 default: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
424 sig_name = "unknown console event"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
425 break; |
5451 | 426 } |
427 | |
428 switch(sig) | |
429 { | |
430 case CTRL_BREAK_EVENT: | |
431 case CTRL_C_EVENT: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
432 w32_raise (SIGINT); |
5451 | 433 break; |
434 | |
435 case CTRL_CLOSE_EVENT: | |
436 case CTRL_LOGOFF_EVENT: | |
437 case CTRL_SHUTDOWN_EVENT: | |
438 default: | |
439 // We should do the following: | |
440 // clean_up_and_exit (0); | |
441 // We can't because we aren't running in the normal Octave thread. | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
442 user_abort(sig_name, sig); |
5451 | 443 break; |
444 } | |
445 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11555
diff
changeset
|
446 // Return TRUE if the event was handled, or FALSE if another handler |
5451 | 447 // should be called. |
5775 | 448 // FIXME check that windows terminates the thread. |
5451 | 449 return TRUE; |
450 } | |
451 #endif /* w32_sigint_handler */ | |
452 | |
453 | |
2705 | 454 octave_interrupt_handler |
2554 | 455 octave_catch_interrupts (void) |
456 { | |
2705 | 457 octave_interrupt_handler retval; |
2554 | 458 |
459 #ifdef SIGINT | |
2705 | 460 retval.int_handler = octave_set_signal_handler (SIGINT, sigint_handler); |
2554 | 461 #endif |
462 | |
463 #ifdef SIGBREAK | |
2705 | 464 retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler); |
2554 | 465 #endif |
2705 | 466 |
5451 | 467 #ifdef USE_W32_SIGINT |
468 | |
469 // Intercept windows console control events. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11555
diff
changeset
|
470 // Note that the windows console signal handlers chain, so if |
5451 | 471 // install_signal_handlers is called more than once in the same program, |
472 // then first call the following to avoid duplicates: | |
473 // | |
474 // SetConsoleCtrlHandler (w32_sigint_handler, FALSE); | |
475 | |
476 if (! SetConsoleCtrlHandler (w32_sigint_handler, TRUE)) | |
477 error ("SetConsoleCtrlHandler failed with %ld\n", GetLastError ()); | |
478 | |
479 w32_set_quiet_shutdown (); | |
480 | |
481 #endif | |
482 | |
2705 | 483 return retval; |
2554 | 484 } |
485 | |
2705 | 486 octave_interrupt_handler |
487 octave_ignore_interrupts (void) | |
2554 | 488 { |
2705 | 489 octave_interrupt_handler retval; |
490 | |
2554 | 491 #ifdef SIGINT |
2705 | 492 retval.int_handler = octave_set_signal_handler (SIGINT, SIG_IGN); |
2554 | 493 #endif |
494 | |
495 #ifdef SIGBREAK | |
2705 | 496 retval.brk_handler = octave_set_signal_handler (SIGBREAK, SIG_IGN); |
2554 | 497 #endif |
2705 | 498 |
499 return retval; | |
500 } | |
501 | |
502 octave_interrupt_handler | |
5770 | 503 octave_set_interrupt_handler (const volatile octave_interrupt_handler& h, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
504 bool restart_syscalls) |
2705 | 505 { |
506 octave_interrupt_handler retval; | |
507 | |
508 #ifdef SIGINT | |
5770 | 509 retval.int_handler = octave_set_signal_handler (SIGINT, h.int_handler, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
510 restart_syscalls); |
2705 | 511 #endif |
512 | |
513 #ifdef SIGBREAK | |
5770 | 514 retval.brk_handler = octave_set_signal_handler (SIGBREAK, h.brk_handler, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
515 restart_syscalls); |
2705 | 516 #endif |
517 | |
518 return retval; | |
1651 | 519 } |
520 | |
635 | 521 // Install all the handlers for the signals we might care about. |
522 | |
1 | 523 void |
524 install_signal_handlers (void) | |
525 { | |
5142 | 526 for (int i = 0; i < NSIG; i++) |
527 octave_signals_caught[i] = false; | |
528 | |
2554 | 529 octave_catch_interrupts (); |
530 | |
1 | 531 #ifdef SIGABRT |
1446 | 532 octave_set_signal_handler (SIGABRT, generic_sig_handler); |
1 | 533 #endif |
534 | |
535 #ifdef SIGALRM | |
1446 | 536 octave_set_signal_handler (SIGALRM, generic_sig_handler); |
1 | 537 #endif |
538 | |
539 #ifdef SIGBUS | |
1446 | 540 octave_set_signal_handler (SIGBUS, generic_sig_handler); |
1 | 541 #endif |
542 | |
1230 | 543 #ifdef SIGCHLD |
1446 | 544 octave_set_signal_handler (SIGCHLD, sigchld_handler); |
1230 | 545 #endif |
546 | |
3174 | 547 // SIGCLD |
548 // SIGCONT | |
549 | |
1 | 550 #ifdef SIGEMT |
1446 | 551 octave_set_signal_handler (SIGEMT, generic_sig_handler); |
1 | 552 #endif |
553 | |
554 #ifdef SIGFPE | |
1373 | 555 #if defined (__alpha__) |
1446 | 556 octave_set_signal_handler (SIGFPE, sigfpe_handler); |
1373 | 557 #else |
1446 | 558 octave_set_signal_handler (SIGFPE, generic_sig_handler); |
1 | 559 #endif |
1373 | 560 #endif |
1 | 561 |
562 #ifdef SIGHUP | |
4449 | 563 octave_set_signal_handler (SIGHUP, sig_hup_or_term_handler); |
1 | 564 #endif |
565 | |
566 #ifdef SIGILL | |
1446 | 567 octave_set_signal_handler (SIGILL, generic_sig_handler); |
1 | 568 #endif |
569 | |
3174 | 570 // SIGINFO |
571 // SIGINT | |
572 | |
1 | 573 #ifdef SIGIOT |
1446 | 574 octave_set_signal_handler (SIGIOT, generic_sig_handler); |
1 | 575 #endif |
576 | |
577 #ifdef SIGLOST | |
1446 | 578 octave_set_signal_handler (SIGLOST, generic_sig_handler); |
1 | 579 #endif |
580 | |
581 #ifdef SIGPIPE | |
1446 | 582 octave_set_signal_handler (SIGPIPE, sigpipe_handler); |
1 | 583 #endif |
584 | |
585 #ifdef SIGPOLL | |
1446 | 586 octave_set_signal_handler (SIGPOLL, SIG_IGN); |
1 | 587 #endif |
588 | |
5866 | 589 // SIGPROF |
3174 | 590 // SIGPWR |
591 | |
1 | 592 #ifdef SIGQUIT |
1446 | 593 octave_set_signal_handler (SIGQUIT, generic_sig_handler); |
1 | 594 #endif |
595 | |
596 #ifdef SIGSEGV | |
1446 | 597 octave_set_signal_handler (SIGSEGV, generic_sig_handler); |
1 | 598 #endif |
599 | |
3174 | 600 // SIGSTOP |
601 | |
1 | 602 #ifdef SIGSYS |
1446 | 603 octave_set_signal_handler (SIGSYS, generic_sig_handler); |
1 | 604 #endif |
605 | |
606 #ifdef SIGTERM | |
4449 | 607 octave_set_signal_handler (SIGTERM, sig_hup_or_term_handler); |
1 | 608 #endif |
609 | |
610 #ifdef SIGTRAP | |
1446 | 611 octave_set_signal_handler (SIGTRAP, generic_sig_handler); |
1 | 612 #endif |
613 | |
3174 | 614 // SIGTSTP |
615 // SIGTTIN | |
616 // SIGTTOU | |
617 // SIGURG | |
618 | |
1 | 619 #ifdef SIGUSR1 |
1446 | 620 octave_set_signal_handler (SIGUSR1, generic_sig_handler); |
1 | 621 #endif |
622 | |
623 #ifdef SIGUSR2 | |
1446 | 624 octave_set_signal_handler (SIGUSR2, generic_sig_handler); |
1 | 625 #endif |
626 | |
627 #ifdef SIGVTALRM | |
1446 | 628 octave_set_signal_handler (SIGVTALRM, generic_sig_handler); |
1 | 629 #endif |
630 | |
895 | 631 #ifdef SIGIO |
1446 | 632 octave_set_signal_handler (SIGIO, SIG_IGN); |
895 | 633 #endif |
634 | |
3343 | 635 #if 0 |
3281 | 636 #ifdef SIGWINCH |
637 octave_set_signal_handler (SIGWINCH, sigwinch_handler); | |
638 #endif | |
3343 | 639 #endif |
3174 | 640 |
1 | 641 #ifdef SIGXCPU |
1446 | 642 octave_set_signal_handler (SIGXCPU, generic_sig_handler); |
1 | 643 #endif |
644 | |
645 #ifdef SIGXFSZ | |
1446 | 646 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); |
1 | 647 #endif |
5451 | 648 |
1 | 649 } |
650 | |
11066
e678346a47d9
toplev.cc, sighandlers.cc, utils.cc, octave.cc, pt-eval.cc pt-idx.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
651 static octave_scalar_map |
4294 | 652 make_sig_struct (void) |
653 { | |
11066
e678346a47d9
toplev.cc, sighandlers.cc, utils.cc, octave.cc, pt-eval.cc pt-idx.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
654 octave_scalar_map m; |
4294 | 655 |
656 #ifdef SIGABRT | |
4675 | 657 m.assign ("ABRT", SIGABRT); |
4294 | 658 #endif |
659 | |
660 #ifdef SIGALRM | |
4675 | 661 m.assign ("ALRM", SIGALRM); |
4294 | 662 #endif |
663 | |
664 #ifdef SIGBUS | |
4675 | 665 m.assign ("BUS", SIGBUS); |
4294 | 666 #endif |
667 | |
668 #ifdef SIGCHLD | |
4675 | 669 m.assign ("CHLD", SIGCHLD); |
4294 | 670 #endif |
671 | |
672 #ifdef SIGCLD | |
4675 | 673 m.assign ("CLD", SIGCLD); |
4294 | 674 #endif |
675 | |
676 #ifdef SIGCONT | |
4675 | 677 m.assign ("CONT", SIGCONT); |
4294 | 678 #endif |
679 | |
680 #ifdef SIGEMT | |
4675 | 681 m.assign ("EMT", SIGEMT); |
4294 | 682 #endif |
683 | |
684 #ifdef SIGFPE | |
4675 | 685 m.assign ("FPE", SIGFPE); |
4294 | 686 #endif |
687 | |
688 #ifdef SIGHUP | |
4675 | 689 m.assign ("HUP", SIGHUP); |
4294 | 690 #endif |
691 | |
692 #ifdef SIGILL | |
4675 | 693 m.assign ("ILL", SIGILL); |
4294 | 694 #endif |
695 | |
696 #ifdef SIGINFO | |
4675 | 697 m.assign ("INFO", SIGINFO); |
4294 | 698 #endif |
699 | |
700 #ifdef SIGINT | |
4675 | 701 m.assign ("INT", SIGINT); |
4294 | 702 #endif |
703 | |
704 #ifdef SIGIOT | |
4675 | 705 m.assign ("IOT", SIGIOT); |
4294 | 706 #endif |
707 | |
708 #ifdef SIGLOST | |
4675 | 709 m.assign ("LOST", SIGLOST); |
4294 | 710 #endif |
711 | |
712 #ifdef SIGPIPE | |
4675 | 713 m.assign ("PIPE", SIGPIPE); |
4294 | 714 #endif |
715 | |
716 #ifdef SIGPOLL | |
4675 | 717 m.assign ("POLL", SIGPOLL); |
4294 | 718 #endif |
719 | |
720 #ifdef SIGPROF | |
4675 | 721 m.assign ("PROF", SIGPROF); |
4294 | 722 #endif |
723 | |
724 #ifdef SIGPWR | |
4675 | 725 m.assign ("PWR", SIGPWR); |
4294 | 726 #endif |
727 | |
728 #ifdef SIGQUIT | |
4675 | 729 m.assign ("QUIT", SIGQUIT); |
4294 | 730 #endif |
731 | |
732 #ifdef SIGSEGV | |
4675 | 733 m.assign ("SEGV", SIGSEGV); |
4294 | 734 #endif |
735 | |
736 #ifdef SIGSTOP | |
4675 | 737 m.assign ("STOP", SIGSTOP); |
4294 | 738 #endif |
739 | |
740 #ifdef SIGSYS | |
4675 | 741 m.assign ("SYS", SIGSYS); |
4294 | 742 #endif |
743 | |
744 #ifdef SIGTERM | |
4675 | 745 m.assign ("TERM", SIGTERM); |
4294 | 746 #endif |
747 | |
748 #ifdef SIGTRAP | |
4675 | 749 m.assign ("TRAP", SIGTRAP); |
4294 | 750 #endif |
751 | |
752 #ifdef SIGTSTP | |
4675 | 753 m.assign ("TSTP", SIGTSTP); |
4294 | 754 #endif |
755 | |
756 #ifdef SIGTTIN | |
4675 | 757 m.assign ("TTIN", SIGTTIN); |
4294 | 758 #endif |
759 | |
760 #ifdef SIGTTOU | |
4675 | 761 m.assign ("TTOU", SIGTTOU); |
4294 | 762 #endif |
763 | |
764 #ifdef SIGURG | |
4675 | 765 m.assign ("URG", SIGURG); |
4294 | 766 #endif |
767 | |
768 #ifdef SIGUSR1 | |
4675 | 769 m.assign ("USR1", SIGUSR1); |
4294 | 770 #endif |
771 | |
772 #ifdef SIGUSR2 | |
4675 | 773 m.assign ("USR2", SIGUSR2); |
4294 | 774 #endif |
775 | |
776 #ifdef SIGVTALRM | |
4675 | 777 m.assign ("VTALRM", SIGVTALRM); |
4294 | 778 #endif |
779 | |
780 #ifdef SIGIO | |
4675 | 781 m.assign ("IO", SIGIO); |
4294 | 782 #endif |
783 | |
784 #ifdef SIGWINCH | |
4675 | 785 m.assign ("WINCH", SIGWINCH); |
4294 | 786 #endif |
787 | |
788 #ifdef SIGXCPU | |
4675 | 789 m.assign ("XCPU", SIGXCPU); |
4294 | 790 #endif |
791 | |
792 #ifdef SIGXFSZ | |
4675 | 793 m.assign ("XFSZ", SIGXFSZ); |
4294 | 794 #endif |
795 | |
796 return m; | |
797 } | |
798 | |
5142 | 799 octave_child_list::octave_child_list_rep *octave_child_list::instance = 0; |
5128 | 800 |
2926 | 801 bool |
802 octave_child_list::instance_ok (void) | |
803 { | |
804 bool retval = true; | |
805 | |
806 if (! instance) | |
5142 | 807 instance = new octave_child_list_rep (); |
2926 | 808 |
809 if (! instance) | |
810 { | |
811 ::error ("unable to create child list object!"); | |
812 | |
813 retval = false; | |
814 } | |
815 | |
816 return retval; | |
817 } | |
818 | |
819 void | |
5142 | 820 octave_child_list::insert (pid_t pid, octave_child::child_event_handler f) |
821 { | |
822 if (instance_ok ()) | |
823 instance->insert (pid, f); | |
824 } | |
825 | |
826 void | |
827 octave_child_list::reap (void) | |
2926 | 828 { |
829 if (instance_ok ()) | |
5142 | 830 instance->reap (); |
831 } | |
832 | |
833 bool | |
834 octave_child_list::wait (void) | |
835 { | |
836 return (instance_ok ()) ? instance->wait () : false; | |
2926 | 837 } |
838 | |
5142 | 839 class pid_equal |
840 { | |
841 public: | |
842 | |
843 pid_equal (pid_t v) : val (v) { } | |
844 | |
845 bool operator () (const octave_child& oc) const { return oc.pid == val; } | |
846 | |
847 private: | |
848 | |
849 pid_t val; | |
850 }; | |
851 | |
2926 | 852 void |
853 octave_child_list::remove (pid_t pid) | |
854 { | |
855 if (instance_ok ()) | |
5142 | 856 instance->remove_if (pid_equal (pid)); |
2926 | 857 } |
858 | |
5142 | 859 #define OCL_REP octave_child_list::octave_child_list_rep |
2926 | 860 |
5142 | 861 void |
862 OCL_REP::insert (pid_t pid, octave_child::child_event_handler f) | |
2926 | 863 { |
5142 | 864 append (octave_child (pid, f)); |
2926 | 865 } |
866 | |
2209 | 867 void |
5142 | 868 OCL_REP::reap (void) |
2209 | 869 { |
5142 | 870 // Mark the record for PID invalid. |
2209 | 871 |
5142 | 872 for (iterator p = begin (); p != end (); p++) |
873 { | |
874 // The call to the octave_child::child_event_handler might | |
875 // invalidate the iterator (for example, by calling | |
876 // octave_child_list::remove), so we increment the iterator | |
877 // here. | |
2209 | 878 |
5142 | 879 octave_child& oc = *p; |
2209 | 880 |
5142 | 881 if (oc.have_status) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
882 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
883 oc.have_status = 0; |
5142 | 884 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
885 octave_child::child_event_handler f = oc.handler; |
5142 | 886 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
887 if (f && f (oc.pid, oc.status)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
888 oc.pid = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
889 } |
2209 | 890 } |
891 | |
5142 | 892 remove_if (pid_equal (-1)); |
2209 | 893 } |
894 | |
5142 | 895 // Wait on our children and record any changes in their status. |
896 | |
897 bool | |
898 OCL_REP::wait (void) | |
2210 | 899 { |
5142 | 900 bool retval = false; |
2210 | 901 |
5142 | 902 for (iterator p = begin (); p != end (); p++) |
2210 | 903 { |
5142 | 904 octave_child& oc = *p; |
905 | |
906 pid_t pid = oc.pid; | |
907 | |
908 if (pid > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
909 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
910 int status; |
2210 | 911 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
912 if (octave_syscalls::waitpid (pid, &status, WNOHANG) > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
913 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
914 oc.have_status = 1; |
5142 | 915 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
916 oc.status = status; |
5142 | 917 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
918 retval = true; |
5142 | 919 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
920 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
921 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
922 } |
2210 | 923 } |
924 | |
5142 | 925 return retval; |
2210 | 926 } |
927 | |
5780 | 928 DEFUN (SIG, args, , |
929 "-*- texinfo -*-\n\ | |
930 @deftypefn {Built-in Function} {} SIG ()\n\ | |
931 Return a structure containing Unix signal names and their defined values.\n\ | |
932 @end deftypefn") | |
933 { | |
934 octave_value retval; | |
935 | |
936 if (args.length () == 0) | |
937 { | |
11066
e678346a47d9
toplev.cc, sighandlers.cc, utils.cc, octave.cc, pt-eval.cc pt-idx.cc: Octave_map to octave_map and octave_scalar_map conversion
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
938 static octave_scalar_map m = make_sig_struct (); |
5780 | 939 |
940 retval = m; | |
941 } | |
942 else | |
5823 | 943 print_usage (); |
5780 | 944 |
945 return retval; | |
946 } | |
947 | |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
948 /* |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
949 %!error SIG (1); |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
950 %!assert (isstruct (SIG ())); |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
951 %!assert (! isempty (SIG ())); |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
952 */ |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
953 |
5794 | 954 DEFUN (debug_on_interrupt, args, nargout, |
955 "-*- texinfo -*-\n\ | |
10840 | 956 @deftypefn {Built-in Function} {@var{val} =} debug_on_interrupt ()\n\ |
5794 | 957 @deftypefnx {Built-in Function} {@var{old_val} =} debug_on_interrupt (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
958 @deftypefnx {Built-in Function} {} debug_on_interrupt (@var{new_val}, \"local\")\n\ |
5794 | 959 Query or set the internal variable that controls whether Octave will try\n\ |
960 to enter debugging mode when it receives an interrupt signal (typically\n\ | |
961 generated with @kbd{C-c}). If a second interrupt signal is received\n\ | |
962 before reaching the debugging mode, a normal interrupt will occur.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
963 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
964 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
965 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
966 variable value is restored when exiting the function.\n\ |
5794 | 967 @end deftypefn") |
4449 | 968 { |
5794 | 969 return SET_INTERNAL_VARIABLE (debug_on_interrupt); |
4449 | 970 } |
971 | |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
972 /* |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
973 %!error (debug_on_interrupt (1, 2)); |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
974 %!test |
12832 | 975 %! orig_val = debug_on_interrupt (); |
976 %! old_val = debug_on_interrupt (! orig_val); | |
977 %! assert (orig_val, old_val); | |
978 %! assert (debug_on_interrupt (), ! orig_val); | |
979 %! debug_on_interrupt (orig_val); | |
980 %! assert (debug_on_interrupt (), orig_val); | |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
981 */ |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
982 |
5794 | 983 DEFUN (sighup_dumps_octave_core, args, nargout, |
984 "-*- texinfo -*-\n\ | |
10840 | 985 @deftypefn {Built-in Function} {@var{val} =} sighup_dumps_octave_core ()\n\ |
5794 | 986 @deftypefnx {Built-in Function} {@var{old_val} =} sighup_dumps_octave_core (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
987 @deftypefnx {Built-in Function} {} sighup_dumps_octave_core (@var{new_val}, \"local\")\n\ |
5794 | 988 Query or set the internal variable that controls whether Octave tries\n\ |
6653 | 989 to save all current variables to the file \"octave-core\" if it receives\n\ |
5794 | 990 a hangup signal.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
991 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
992 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
993 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
994 variable value is restored when exiting the function.\n\ |
5794 | 995 @end deftypefn") |
4185 | 996 { |
5794 | 997 return SET_INTERNAL_VARIABLE (sighup_dumps_octave_core); |
998 } | |
4294 | 999 |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1000 /* |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1001 %!error (sighup_dumps_octave_core (1, 2)); |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1002 %!test |
12832 | 1003 %! orig_val = sighup_dumps_octave_core (); |
1004 %! old_val = sighup_dumps_octave_core (! orig_val); | |
1005 %! assert (orig_val, old_val); | |
1006 %! assert (sighup_dumps_octave_core (), ! orig_val); | |
1007 %! sighup_dumps_octave_core (orig_val); | |
1008 %! assert (sighup_dumps_octave_core (), orig_val); | |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1009 */ |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1010 |
5794 | 1011 DEFUN (sigterm_dumps_octave_core, args, nargout, |
1012 "-*- texinfo -*-\n\ | |
10840 | 1013 @deftypefn {Built-in Function} {@var{val} =} sigterm_dumps_octave_core ()\n\ |
5794 | 1014 @deftypefnx {Built-in Function} {@var{old_val} =} sigterm_dumps_octave_core (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
1015 @deftypefnx {Built-in Function} {} sigterm_dumps_octave_core (@var{new_val}, \"local\")\n\ |
5794 | 1016 Query or set the internal variable that controls whether Octave tries\n\ |
6653 | 1017 to save all current variables to the file \"octave-core\" if it receives\n\ |
5794 | 1018 a terminate signal.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
1019 \n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
1020 When called from inside a function with the \"local\" option, the variable is\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
1021 changed locally for the function and any subroutines it calls. The original\n\ |
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
1022 variable value is restored when exiting the function.\n\ |
5794 | 1023 @end deftypefn") |
1024 { | |
1025 return SET_INTERNAL_VARIABLE (sigterm_dumps_octave_core); | |
4185 | 1026 } |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1027 |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1028 /* |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1029 %!error (sigterm_dumps_octave_core (1, 2)); |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1030 %!test |
12832 | 1031 %! orig_val = sigterm_dumps_octave_core (); |
1032 %! old_val = sigterm_dumps_octave_core (! orig_val); | |
1033 %! assert (orig_val, old_val); | |
1034 %! assert (sigterm_dumps_octave_core (), ! orig_val); | |
1035 %! sigterm_dumps_octave_core (orig_val); | |
1036 %! assert (sigterm_dumps_octave_core (), orig_val); | |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
1037 */ |