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