Mercurial > hg > octave-lyh
annotate libinterp/corefcn/sighandlers.cc @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | bc924baa2c4e |
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. |
15595
6e780fb15c14
Make Vdebug_on_interrupt not be static
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
64 bool Vdebug_on_interrupt = false; |
4185 | 65 |
14889
577df411e0c7
rename octave-core file to octave-workspace
John W. Eaton <jwe@octave.org>
parents:
14861
diff
changeset
|
66 // Allow users to avoid writing octave-workspace for SIGHUP (sent by |
4449 | 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: |
14893 | 150 std::cerr << "warning: floating point exception" << std::endl; |
10315
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: |
14893 | 155 std::cerr << "warning: broken pipe" << std::endl; |
10315
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 } |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14443
diff
changeset
|
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 } |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14443
diff
changeset
|
271 #endif /* defined (__alpha__) */ |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14443
diff
changeset
|
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 { | |
5844 | 381 user_abort (strsignal (sig), sig); |
1 | 382 } |
383 | |
4064 | 384 #ifdef SIGPIPE |
10246 | 385 static void |
1488 | 386 sigpipe_handler (int /* sig */) |
1 | 387 { |
5142 | 388 octave_signal_caught = 1; |
389 | |
390 octave_signals_caught[SIGPIPE] = true; | |
1 | 391 |
1358 | 392 // Don't loop forever on account of this. |
393 | |
5142 | 394 if (pipe_handler_error_count++ > 100 && octave_interrupt_state >= 0) |
4787 | 395 octave_interrupt_state++; |
1 | 396 } |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14443
diff
changeset
|
397 #endif /* defined (SIGPIPE) */ |
1 | 398 |
2705 | 399 octave_interrupt_handler |
2554 | 400 octave_catch_interrupts (void) |
401 { | |
2705 | 402 octave_interrupt_handler retval; |
2554 | 403 |
404 #ifdef SIGINT | |
2705 | 405 retval.int_handler = octave_set_signal_handler (SIGINT, sigint_handler); |
2554 | 406 #endif |
407 | |
408 #ifdef SIGBREAK | |
2705 | 409 retval.brk_handler = octave_set_signal_handler (SIGBREAK, sigint_handler); |
2554 | 410 #endif |
2705 | 411 |
412 return retval; | |
2554 | 413 } |
414 | |
2705 | 415 octave_interrupt_handler |
416 octave_ignore_interrupts (void) | |
2554 | 417 { |
2705 | 418 octave_interrupt_handler retval; |
419 | |
2554 | 420 #ifdef SIGINT |
2705 | 421 retval.int_handler = octave_set_signal_handler (SIGINT, SIG_IGN); |
2554 | 422 #endif |
423 | |
424 #ifdef SIGBREAK | |
2705 | 425 retval.brk_handler = octave_set_signal_handler (SIGBREAK, SIG_IGN); |
2554 | 426 #endif |
2705 | 427 |
428 return retval; | |
429 } | |
430 | |
431 octave_interrupt_handler | |
5770 | 432 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
|
433 bool restart_syscalls) |
2705 | 434 { |
435 octave_interrupt_handler retval; | |
436 | |
437 #ifdef SIGINT | |
5770 | 438 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
|
439 restart_syscalls); |
2705 | 440 #endif |
441 | |
442 #ifdef SIGBREAK | |
5770 | 443 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
|
444 restart_syscalls); |
2705 | 445 #endif |
446 | |
447 return retval; | |
1651 | 448 } |
449 | |
635 | 450 // Install all the handlers for the signals we might care about. |
451 | |
1 | 452 void |
453 install_signal_handlers (void) | |
454 { | |
5142 | 455 for (int i = 0; i < NSIG; i++) |
456 octave_signals_caught[i] = false; | |
457 | |
2554 | 458 octave_catch_interrupts (); |
459 | |
1 | 460 #ifdef SIGABRT |
1446 | 461 octave_set_signal_handler (SIGABRT, generic_sig_handler); |
1 | 462 #endif |
463 | |
464 #ifdef SIGALRM | |
1446 | 465 octave_set_signal_handler (SIGALRM, generic_sig_handler); |
1 | 466 #endif |
467 | |
468 #ifdef SIGBUS | |
1446 | 469 octave_set_signal_handler (SIGBUS, generic_sig_handler); |
1 | 470 #endif |
471 | |
1230 | 472 #ifdef SIGCHLD |
1446 | 473 octave_set_signal_handler (SIGCHLD, sigchld_handler); |
1230 | 474 #endif |
475 | |
3174 | 476 // SIGCLD |
477 // SIGCONT | |
478 | |
1 | 479 #ifdef SIGEMT |
1446 | 480 octave_set_signal_handler (SIGEMT, generic_sig_handler); |
1 | 481 #endif |
482 | |
483 #ifdef SIGFPE | |
1373 | 484 #if defined (__alpha__) |
1446 | 485 octave_set_signal_handler (SIGFPE, sigfpe_handler); |
1373 | 486 #else |
1446 | 487 octave_set_signal_handler (SIGFPE, generic_sig_handler); |
1 | 488 #endif |
1373 | 489 #endif |
1 | 490 |
491 #ifdef SIGHUP | |
4449 | 492 octave_set_signal_handler (SIGHUP, sig_hup_or_term_handler); |
1 | 493 #endif |
494 | |
495 #ifdef SIGILL | |
1446 | 496 octave_set_signal_handler (SIGILL, generic_sig_handler); |
1 | 497 #endif |
498 | |
3174 | 499 // SIGINFO |
500 // SIGINT | |
501 | |
1 | 502 #ifdef SIGIOT |
1446 | 503 octave_set_signal_handler (SIGIOT, generic_sig_handler); |
1 | 504 #endif |
505 | |
506 #ifdef SIGLOST | |
1446 | 507 octave_set_signal_handler (SIGLOST, generic_sig_handler); |
1 | 508 #endif |
509 | |
510 #ifdef SIGPIPE | |
1446 | 511 octave_set_signal_handler (SIGPIPE, sigpipe_handler); |
1 | 512 #endif |
513 | |
514 #ifdef SIGPOLL | |
1446 | 515 octave_set_signal_handler (SIGPOLL, SIG_IGN); |
1 | 516 #endif |
517 | |
5866 | 518 // SIGPROF |
3174 | 519 // SIGPWR |
520 | |
1 | 521 #ifdef SIGQUIT |
1446 | 522 octave_set_signal_handler (SIGQUIT, generic_sig_handler); |
1 | 523 #endif |
524 | |
525 #ifdef SIGSEGV | |
1446 | 526 octave_set_signal_handler (SIGSEGV, generic_sig_handler); |
1 | 527 #endif |
528 | |
3174 | 529 // SIGSTOP |
530 | |
1 | 531 #ifdef SIGSYS |
1446 | 532 octave_set_signal_handler (SIGSYS, generic_sig_handler); |
1 | 533 #endif |
534 | |
535 #ifdef SIGTERM | |
4449 | 536 octave_set_signal_handler (SIGTERM, sig_hup_or_term_handler); |
1 | 537 #endif |
538 | |
539 #ifdef SIGTRAP | |
1446 | 540 octave_set_signal_handler (SIGTRAP, generic_sig_handler); |
1 | 541 #endif |
542 | |
3174 | 543 // SIGTSTP |
544 // SIGTTIN | |
545 // SIGTTOU | |
546 // SIGURG | |
547 | |
1 | 548 #ifdef SIGUSR1 |
1446 | 549 octave_set_signal_handler (SIGUSR1, generic_sig_handler); |
1 | 550 #endif |
551 | |
552 #ifdef SIGUSR2 | |
1446 | 553 octave_set_signal_handler (SIGUSR2, generic_sig_handler); |
1 | 554 #endif |
555 | |
556 #ifdef SIGVTALRM | |
1446 | 557 octave_set_signal_handler (SIGVTALRM, generic_sig_handler); |
1 | 558 #endif |
559 | |
895 | 560 #ifdef SIGIO |
1446 | 561 octave_set_signal_handler (SIGIO, SIG_IGN); |
895 | 562 #endif |
563 | |
3343 | 564 #if 0 |
3281 | 565 #ifdef SIGWINCH |
566 octave_set_signal_handler (SIGWINCH, sigwinch_handler); | |
567 #endif | |
3343 | 568 #endif |
3174 | 569 |
1 | 570 #ifdef SIGXCPU |
1446 | 571 octave_set_signal_handler (SIGXCPU, generic_sig_handler); |
1 | 572 #endif |
573 | |
574 #ifdef SIGXFSZ | |
1446 | 575 octave_set_signal_handler (SIGXFSZ, generic_sig_handler); |
1 | 576 #endif |
5451 | 577 |
1 | 578 } |
579 | |
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
|
580 static octave_scalar_map |
4294 | 581 make_sig_struct (void) |
582 { | |
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
|
583 octave_scalar_map m; |
4294 | 584 |
585 #ifdef SIGABRT | |
4675 | 586 m.assign ("ABRT", SIGABRT); |
4294 | 587 #endif |
588 | |
589 #ifdef SIGALRM | |
4675 | 590 m.assign ("ALRM", SIGALRM); |
4294 | 591 #endif |
592 | |
593 #ifdef SIGBUS | |
4675 | 594 m.assign ("BUS", SIGBUS); |
4294 | 595 #endif |
596 | |
597 #ifdef SIGCHLD | |
4675 | 598 m.assign ("CHLD", SIGCHLD); |
4294 | 599 #endif |
600 | |
601 #ifdef SIGCLD | |
4675 | 602 m.assign ("CLD", SIGCLD); |
4294 | 603 #endif |
604 | |
605 #ifdef SIGCONT | |
4675 | 606 m.assign ("CONT", SIGCONT); |
4294 | 607 #endif |
608 | |
609 #ifdef SIGEMT | |
4675 | 610 m.assign ("EMT", SIGEMT); |
4294 | 611 #endif |
612 | |
613 #ifdef SIGFPE | |
4675 | 614 m.assign ("FPE", SIGFPE); |
4294 | 615 #endif |
616 | |
617 #ifdef SIGHUP | |
4675 | 618 m.assign ("HUP", SIGHUP); |
4294 | 619 #endif |
620 | |
621 #ifdef SIGILL | |
4675 | 622 m.assign ("ILL", SIGILL); |
4294 | 623 #endif |
624 | |
625 #ifdef SIGINFO | |
4675 | 626 m.assign ("INFO", SIGINFO); |
4294 | 627 #endif |
628 | |
629 #ifdef SIGINT | |
4675 | 630 m.assign ("INT", SIGINT); |
4294 | 631 #endif |
632 | |
16706
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
633 #ifdef SIGIO |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
634 m.assign ("IO", SIGIO); |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
635 #endif |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
636 |
4294 | 637 #ifdef SIGIOT |
4675 | 638 m.assign ("IOT", SIGIOT); |
4294 | 639 #endif |
640 | |
16706
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
641 #ifdef SIGKILL |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
642 m.assign ("KILL", SIGKILL); |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
643 #endif |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
644 |
4294 | 645 #ifdef SIGLOST |
4675 | 646 m.assign ("LOST", SIGLOST); |
4294 | 647 #endif |
648 | |
649 #ifdef SIGPIPE | |
4675 | 650 m.assign ("PIPE", SIGPIPE); |
4294 | 651 #endif |
652 | |
653 #ifdef SIGPOLL | |
4675 | 654 m.assign ("POLL", SIGPOLL); |
4294 | 655 #endif |
656 | |
657 #ifdef SIGPROF | |
4675 | 658 m.assign ("PROF", SIGPROF); |
4294 | 659 #endif |
660 | |
661 #ifdef SIGPWR | |
4675 | 662 m.assign ("PWR", SIGPWR); |
4294 | 663 #endif |
664 | |
665 #ifdef SIGQUIT | |
4675 | 666 m.assign ("QUIT", SIGQUIT); |
4294 | 667 #endif |
668 | |
669 #ifdef SIGSEGV | |
4675 | 670 m.assign ("SEGV", SIGSEGV); |
4294 | 671 #endif |
672 | |
16706
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
673 #ifdef SIGSTKFLT |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
674 m.assign ("STKFLT", SIGSTKFLT); |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
675 #endif |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
676 |
4294 | 677 #ifdef SIGSTOP |
4675 | 678 m.assign ("STOP", SIGSTOP); |
4294 | 679 #endif |
680 | |
681 #ifdef SIGSYS | |
4675 | 682 m.assign ("SYS", SIGSYS); |
4294 | 683 #endif |
684 | |
685 #ifdef SIGTERM | |
4675 | 686 m.assign ("TERM", SIGTERM); |
4294 | 687 #endif |
688 | |
689 #ifdef SIGTRAP | |
4675 | 690 m.assign ("TRAP", SIGTRAP); |
4294 | 691 #endif |
692 | |
693 #ifdef SIGTSTP | |
4675 | 694 m.assign ("TSTP", SIGTSTP); |
4294 | 695 #endif |
696 | |
697 #ifdef SIGTTIN | |
4675 | 698 m.assign ("TTIN", SIGTTIN); |
4294 | 699 #endif |
700 | |
701 #ifdef SIGTTOU | |
4675 | 702 m.assign ("TTOU", SIGTTOU); |
4294 | 703 #endif |
704 | |
16706
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
705 #ifdef SIGUNUSED |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
706 m.assign ("UNUSED", SIGUNUSED); |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
707 #endif |
736dca8371ee
include more signals in SIG function (bug #39089)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
16404
diff
changeset
|
708 |
4294 | 709 #ifdef SIGURG |
4675 | 710 m.assign ("URG", SIGURG); |
4294 | 711 #endif |
712 | |
713 #ifdef SIGUSR1 | |
4675 | 714 m.assign ("USR1", SIGUSR1); |
4294 | 715 #endif |
716 | |
717 #ifdef SIGUSR2 | |
4675 | 718 m.assign ("USR2", SIGUSR2); |
4294 | 719 #endif |
720 | |
721 #ifdef SIGVTALRM | |
4675 | 722 m.assign ("VTALRM", SIGVTALRM); |
4294 | 723 #endif |
724 | |
725 #ifdef SIGWINCH | |
4675 | 726 m.assign ("WINCH", SIGWINCH); |
4294 | 727 #endif |
728 | |
729 #ifdef SIGXCPU | |
4675 | 730 m.assign ("XCPU", SIGXCPU); |
4294 | 731 #endif |
732 | |
733 #ifdef SIGXFSZ | |
4675 | 734 m.assign ("XFSZ", SIGXFSZ); |
4294 | 735 #endif |
736 | |
737 return m; | |
738 } | |
739 | |
5142 | 740 octave_child_list::octave_child_list_rep *octave_child_list::instance = 0; |
5128 | 741 |
2926 | 742 bool |
743 octave_child_list::instance_ok (void) | |
744 { | |
745 bool retval = true; | |
746 | |
747 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
748 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
749 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
|
750 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
751 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13951
diff
changeset
|
752 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
|
753 } |
2926 | 754 |
755 if (! instance) | |
756 { | |
757 ::error ("unable to create child list object!"); | |
758 | |
759 retval = false; | |
760 } | |
761 | |
762 return retval; | |
763 } | |
764 | |
765 void | |
5142 | 766 octave_child_list::insert (pid_t pid, octave_child::child_event_handler f) |
767 { | |
768 if (instance_ok ()) | |
769 instance->insert (pid, f); | |
770 } | |
771 | |
772 void | |
773 octave_child_list::reap (void) | |
2926 | 774 { |
775 if (instance_ok ()) | |
5142 | 776 instance->reap (); |
777 } | |
778 | |
779 bool | |
780 octave_child_list::wait (void) | |
781 { | |
782 return (instance_ok ()) ? instance->wait () : false; | |
2926 | 783 } |
784 | |
5142 | 785 class pid_equal |
786 { | |
787 public: | |
788 | |
789 pid_equal (pid_t v) : val (v) { } | |
790 | |
791 bool operator () (const octave_child& oc) const { return oc.pid == val; } | |
792 | |
793 private: | |
794 | |
795 pid_t val; | |
796 }; | |
797 | |
2926 | 798 void |
799 octave_child_list::remove (pid_t pid) | |
800 { | |
801 if (instance_ok ()) | |
5142 | 802 instance->remove_if (pid_equal (pid)); |
2926 | 803 } |
804 | |
5142 | 805 #define OCL_REP octave_child_list::octave_child_list_rep |
2926 | 806 |
5142 | 807 void |
808 OCL_REP::insert (pid_t pid, octave_child::child_event_handler f) | |
2926 | 809 { |
5142 | 810 append (octave_child (pid, f)); |
2926 | 811 } |
812 | |
2209 | 813 void |
5142 | 814 OCL_REP::reap (void) |
2209 | 815 { |
5142 | 816 // Mark the record for PID invalid. |
2209 | 817 |
5142 | 818 for (iterator p = begin (); p != end (); p++) |
819 { | |
820 // The call to the octave_child::child_event_handler might | |
821 // invalidate the iterator (for example, by calling | |
822 // octave_child_list::remove), so we increment the iterator | |
823 // here. | |
2209 | 824 |
5142 | 825 octave_child& oc = *p; |
2209 | 826 |
5142 | 827 if (oc.have_status) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
828 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
829 oc.have_status = 0; |
5142 | 830 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
831 octave_child::child_event_handler f = oc.handler; |
5142 | 832 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
833 if (f && f (oc.pid, oc.status)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
834 oc.pid = -1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
835 } |
2209 | 836 } |
837 | |
5142 | 838 remove_if (pid_equal (-1)); |
2209 | 839 } |
840 | |
5142 | 841 // Wait on our children and record any changes in their status. |
842 | |
843 bool | |
844 OCL_REP::wait (void) | |
2210 | 845 { |
5142 | 846 bool retval = false; |
2210 | 847 |
5142 | 848 for (iterator p = begin (); p != end (); p++) |
2210 | 849 { |
5142 | 850 octave_child& oc = *p; |
851 | |
852 pid_t pid = oc.pid; | |
853 | |
854 if (pid > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
855 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
856 int status; |
2210 | 857 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
858 if (octave_syscalls::waitpid (pid, &status, WNOHANG) > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
859 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
860 oc.have_status = 1; |
5142 | 861 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
862 oc.status = status; |
5142 | 863 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
864 retval = true; |
5142 | 865 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
866 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
867 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10246
diff
changeset
|
868 } |
2210 | 869 } |
870 | |
5142 | 871 return retval; |
2210 | 872 } |
873 | |
5780 | 874 DEFUN (SIG, args, , |
875 "-*- texinfo -*-\n\ | |
876 @deftypefn {Built-in Function} {} SIG ()\n\ | |
877 Return a structure containing Unix signal names and their defined values.\n\ | |
878 @end deftypefn") | |
879 { | |
880 octave_value retval; | |
881 | |
882 if (args.length () == 0) | |
883 { | |
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
|
884 static octave_scalar_map m = make_sig_struct (); |
5780 | 885 |
886 retval = m; | |
887 } | |
888 else | |
5823 | 889 print_usage (); |
5780 | 890 |
891 return retval; | |
892 } | |
893 | |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
894 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
895 %!assert (isstruct (SIG ())) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
896 %!assert (! isempty (SIG ())) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
897 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
898 %!error SIG (1) |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
899 */ |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
900 |
5794 | 901 DEFUN (debug_on_interrupt, args, nargout, |
902 "-*- texinfo -*-\n\ | |
10840 | 903 @deftypefn {Built-in Function} {@var{val} =} debug_on_interrupt ()\n\ |
5794 | 904 @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
|
905 @deftypefnx {Built-in Function} {} debug_on_interrupt (@var{new_val}, \"local\")\n\ |
5794 | 906 Query or set the internal variable that controls whether Octave will try\n\ |
907 to enter debugging mode when it receives an interrupt signal (typically\n\ | |
908 generated with @kbd{C-c}). If a second interrupt signal is received\n\ | |
909 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
|
910 \n\ |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
911 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
912 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
913 The original 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
|
914 @seealso{debug_on_error, debug_on_warning}\n\ |
5794 | 915 @end deftypefn") |
4449 | 916 { |
5794 | 917 return SET_INTERNAL_VARIABLE (debug_on_interrupt); |
4449 | 918 } |
919 | |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
920 /* |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
921 %!test |
12832 | 922 %! orig_val = debug_on_interrupt (); |
923 %! old_val = debug_on_interrupt (! orig_val); | |
924 %! assert (orig_val, old_val); | |
925 %! assert (debug_on_interrupt (), ! orig_val); | |
926 %! debug_on_interrupt (orig_val); | |
927 %! assert (debug_on_interrupt (), orig_val); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
928 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
929 %!error (debug_on_interrupt (1, 2)) |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
930 */ |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
931 |
5794 | 932 DEFUN (sighup_dumps_octave_core, args, nargout, |
933 "-*- texinfo -*-\n\ | |
10840 | 934 @deftypefn {Built-in Function} {@var{val} =} sighup_dumps_octave_core ()\n\ |
5794 | 935 @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
|
936 @deftypefnx {Built-in Function} {} sighup_dumps_octave_core (@var{new_val}, \"local\")\n\ |
5794 | 937 Query or set the internal variable that controls whether Octave tries\n\ |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
938 to save all current variables to the file @file{octave-workspace} if it\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
939 receives a hangup signal.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
940 \n\ |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
941 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
942 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
943 The original variable value is restored when exiting the function.\n\ |
5794 | 944 @end deftypefn") |
4185 | 945 { |
5794 | 946 return SET_INTERNAL_VARIABLE (sighup_dumps_octave_core); |
947 } | |
4294 | 948 |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
949 /* |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
950 %!test |
12832 | 951 %! orig_val = sighup_dumps_octave_core (); |
952 %! old_val = sighup_dumps_octave_core (! orig_val); | |
953 %! assert (orig_val, old_val); | |
954 %! assert (sighup_dumps_octave_core (), ! orig_val); | |
955 %! sighup_dumps_octave_core (orig_val); | |
956 %! assert (sighup_dumps_octave_core (), orig_val); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
957 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
958 %!error (sighup_dumps_octave_core (1, 2)) |
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 |
5794 | 961 DEFUN (sigterm_dumps_octave_core, args, nargout, |
962 "-*- texinfo -*-\n\ | |
10840 | 963 @deftypefn {Built-in Function} {@var{val} =} sigterm_dumps_octave_core ()\n\ |
5794 | 964 @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
|
965 @deftypefnx {Built-in Function} {} sigterm_dumps_octave_core (@var{new_val}, \"local\")\n\ |
5794 | 966 Query or set the internal variable that controls whether Octave tries\n\ |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
967 to save all current variables to the file @file{octave-workspace} if it\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
968 receives a terminate signal.\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
12832
diff
changeset
|
969 \n\ |
17289
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
970 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
971 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
972 The original variable value is restored when exiting the function.\n\ |
5794 | 973 @end deftypefn") |
974 { | |
975 return SET_INTERNAL_VARIABLE (sigterm_dumps_octave_core); | |
4185 | 976 } |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
977 |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
978 /* |
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
979 %!test |
12832 | 980 %! orig_val = sigterm_dumps_octave_core (); |
981 %! old_val = sigterm_dumps_octave_core (! orig_val); | |
982 %! assert (orig_val, old_val); | |
983 %! assert (sigterm_dumps_octave_core (), ! orig_val); | |
984 %! sigterm_dumps_octave_core (orig_val); | |
985 %! assert (sigterm_dumps_octave_core (), orig_val); | |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
986 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14338
diff
changeset
|
987 %!error (sigterm_dumps_octave_core (1, 2)) |
12827
8c6d71520920
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
988 */ |