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