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