Mercurial > octave
comparison libinterp/corefcn/sighandlers.cc @ 31607:aac27ad79be6 stable
maint: Re-indent code after switch to using namespace macros.
* build-env.h, build-env.in.cc, Cell.h, __betainc__.cc, __eigs__.cc,
__ftp__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __magick_read__.cc,
__pchip_deriv__.cc, amd.cc, base-text-renderer.cc, base-text-renderer.h,
besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.h, call-stack.cc,
call-stack.h, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, dasrt.cc, data.cc,
debug.cc, defaults.cc, defaults.h, det.cc, display.cc, display.h, dlmread.cc,
dynamic-ld.cc, dynamic-ld.h, ellipj.cc, environment.cc, environment.h,
error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h,
event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc,
file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h,
gcd.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h,
graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, gsvd.cc, gtk-manager.cc,
gtk-manager.h, help.cc, help.h, hook-fcn.cc, hook-fcn.h, input.cc, input.h,
interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h,
inv.cc, jsondecode.cc, jsonencode.cc, latex-text-renderer.cc,
latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h,
lookup.cc, ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, lsode.cc, lu.cc, mappers.cc,
matrix_type.cc, max.cc, mex.cc, mexproto.h, mxarray.h, mxtypes.in.h,
oct-errno.in.cc, oct-hdf5-types.cc, oct-hist.cc, oct-hist.h, oct-map.cc,
oct-map.h, oct-opengl.h, oct-prcstrm.h, oct-process.cc, oct-process.h,
oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.h,
octave-default-image.h, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc,
pow2.cc, pr-output.cc, psi.cc, qr.cc, quadcc.cc, rand.cc, regexp.cc,
settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xpow.cc,
sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfns.cc, svd.cc,
syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h,
symtab.cc, symtab.h, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h,
text-renderer.cc, text-renderer.h, time.cc, toplev.cc, typecast.cc,
url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h,
variables.cc, variables.h, xdiv.cc, __delaunayn__.cc, __init_fltk__.cc,
__init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audioread.cc, convhulln.cc,
gzip.cc, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc,
cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h,
cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h,
cdef-utils.cc, cdef-utils.h, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc,
ov-base-mat.h, ov-base-scalar.cc, ov-base.cc, ov-base.h, ov-bool-mat.cc,
ov-bool-mat.h, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.h, ov-cell.cc,
ov-ch-mat.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h,
ov-complex.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc,
ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-float.cc,
ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc,
ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-intx.h, ov-java.cc, ov-lazy-idx.cc,
ov-legacy-range.cc, ov-magic-int.cc, ov-mex-fcn.cc, ov-mex-fcn.h,
ov-null-mat.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc,
ov-re-mat.h, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc,
ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, ovl.h,
octave.cc, octave.h, op-b-sbm.cc, op-bm-sbm.cc, op-cs-scm.cc, op-fm-fcm.cc,
op-fs-fcm.cc, op-s-scm.cc, op-scm-cs.cc, op-scm-s.cc, op-sm-cs.cc, ops.h,
anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h,
comment-list.cc, comment-list.h, filepos.h, lex.h, oct-lvalue.cc, oct-lvalue.h,
parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h,
pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h,
pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc,
pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc,
pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.h,
pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h,
pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h,
pt-fcn-handle.cc, pt-fcn-handle.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h,
pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h,
pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-spmd.cc, pt-spmd.h,
pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h,
pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h,
idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h,
aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h,
gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc,
lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h,
oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc,
oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h,
randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h,
sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc,
sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h,
file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h,
lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h,
oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc,
oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h,
action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h,
cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h,
lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h,
lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc,
oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc,
oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc,
oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc,
pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc,
url-transfer.h:
Re-indent code after switch to using namespace macros.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 01 Dec 2022 18:02:15 -0800 |
parents | e88a07dec498 |
children | d9970470108a |
comparison
equal
deleted
inserted
replaced
31605:e88a07dec498 | 31607:aac27ad79be6 |
---|---|
58 #include "utils.h" | 58 #include "utils.h" |
59 #include "variables.h" | 59 #include "variables.h" |
60 | 60 |
61 OCTAVE_BEGIN_NAMESPACE(octave) | 61 OCTAVE_BEGIN_NAMESPACE(octave) |
62 | 62 |
63 // Nonzero means we have already printed a message for this series of | 63 // Nonzero means we have already printed a message for this series of |
64 // SIGPIPES. We assume that the writer will eventually give up. | 64 // SIGPIPES. We assume that the writer will eventually give up. |
65 int pipe_handler_error_count = 0; | 65 int pipe_handler_error_count = 0; |
66 | 66 |
67 // TRUE means we can be interrupted. | 67 // TRUE means we can be interrupted. |
68 bool can_interrupt = false; | 68 bool can_interrupt = false; |
69 | 69 |
70 // TRUE means we should try to enter the debugger on SIGINT. | 70 // TRUE means we should try to enter the debugger on SIGINT. |
71 bool Vdebug_on_interrupt = false; | 71 bool Vdebug_on_interrupt = false; |
72 | 72 |
73 // Allow users to avoid writing octave-workspace for SIGHUP (sent by | 73 // Allow users to avoid writing octave-workspace for SIGHUP (sent by |
74 // closing gnome-terminal, for example). Note that this variable has | 74 // closing gnome-terminal, for example). Note that this variable has |
75 // no effect if Vcrash_dumps_octave_core is FALSE. | 75 // no effect if Vcrash_dumps_octave_core is FALSE. |
76 static bool Vsighup_dumps_octave_core = true; | 76 static bool Vsighup_dumps_octave_core = true; |
77 | 77 |
78 // Similar to Vsighup_dumps_octave_core, but for SIGQUIT signal. | 78 // Similar to Vsighup_dumps_octave_core, but for SIGQUIT signal. |
79 static bool Vsigquit_dumps_octave_core = true; | 79 static bool Vsigquit_dumps_octave_core = true; |
80 | 80 |
81 // Similar to Vsighup_dumps_octave_core, but for SIGTERM signal. | 81 // Similar to Vsighup_dumps_octave_core, but for SIGTERM signal. |
82 static bool Vsigterm_dumps_octave_core = true; | 82 static bool Vsigterm_dumps_octave_core = true; |
83 | 83 |
84 // List of signals we have caught since last call to signal_handler. | 84 // List of signals we have caught since last call to signal_handler. |
85 static bool *signals_caught = nullptr; | 85 static bool *signals_caught = nullptr; |
86 | 86 |
87 static void | 87 static void |
88 my_friendly_exit (int sig, bool save_vars = true) | 88 my_friendly_exit (int sig, bool save_vars = true) |
89 { | 89 { |
90 std::cerr << "fatal: caught signal " | 90 std::cerr << "fatal: caught signal " |
91 << octave_strsignal_wrapper (sig) | 91 << octave_strsignal_wrapper (sig) |
92 << " -- stopping myself..." << std::endl; | 92 << " -- stopping myself..." << std::endl; |
93 | 93 |
94 if (save_vars) | 94 if (save_vars) |
95 { | 95 { |
96 load_save_system& load_save_sys = __get_load_save_system__ (); | 96 load_save_system& load_save_sys = __get_load_save_system__ (); |
97 | 97 |
98 load_save_sys.dump_octave_core (); | 98 load_save_sys.dump_octave_core (); |
99 } | 99 } |
100 | 100 |
101 sysdep_cleanup (); | 101 sysdep_cleanup (); |
102 | 102 |
103 throw exit_exception (1); | 103 throw exit_exception (1); |
104 } | 104 } |
105 | 105 |
106 // Called from octave_quit () to actually do something about the signals | 106 // Called from octave_quit () to actually do something about the signals |
107 // we have caught. | 107 // we have caught. |
108 | 108 |
109 void | 109 void |
110 respond_to_pending_signals (void) | 110 respond_to_pending_signals (void) |
111 { | 111 { |
112 // The list of signals is relatively short, so we will just go | 112 // The list of signals is relatively short, so we will just go |
113 // linearly through the list. | 113 // linearly through the list. |
114 | 114 |
115 // Interrupt signals are currently handled separately. | 115 // Interrupt signals are currently handled separately. |
116 | 116 |
117 static int sigint; | 117 static int sigint; |
118 static const bool have_sigint | 118 static const bool have_sigint |
119 = octave_get_sig_number ("SIGINT", &sigint); | 119 = octave_get_sig_number ("SIGINT", &sigint); |
120 | 120 |
121 static int sigbreak; | 121 static int sigbreak; |
122 static const bool have_sigbreak | 122 static const bool have_sigbreak |
123 = octave_get_sig_number ("SIGBREAK", &sigbreak); | 123 = octave_get_sig_number ("SIGBREAK", &sigbreak); |
124 | 124 |
125 // Termination signals. | 125 // Termination signals. |
126 | 126 |
127 static int sighup; | 127 static int sighup; |
128 static const bool have_sighup | 128 static const bool have_sighup |
129 = octave_get_sig_number ("SIGHUP", &sighup); | 129 = octave_get_sig_number ("SIGHUP", &sighup); |
130 | 130 |
131 static int sigquit; | 131 static int sigquit; |
132 static const bool have_sigquit | 132 static const bool have_sigquit |
133 = octave_get_sig_number ("SIGQUIT", &sigquit); | 133 = octave_get_sig_number ("SIGQUIT", &sigquit); |
134 | 134 |
135 static int sigterm; | 135 static int sigterm; |
136 static const bool have_sigterm | 136 static const bool have_sigterm |
137 = octave_get_sig_number ("SIGTERM", &sigterm); | 137 = octave_get_sig_number ("SIGTERM", &sigterm); |
138 | 138 |
139 // Alarm signals. | 139 // Alarm signals. |
140 | 140 |
141 static int sigalrm; | 141 static int sigalrm; |
142 static const bool have_sigalrm | 142 static const bool have_sigalrm |
143 = octave_get_sig_number ("SIGALRM", &sigalrm); | 143 = octave_get_sig_number ("SIGALRM", &sigalrm); |
144 | 144 |
145 static int sigvtalrm; | 145 static int sigvtalrm; |
146 static const bool have_sigvtalrm | 146 static const bool have_sigvtalrm |
147 = octave_get_sig_number ("SIGVTALRM", &sigvtalrm); | 147 = octave_get_sig_number ("SIGVTALRM", &sigvtalrm); |
148 | 148 |
149 // I/O signals. | 149 // I/O signals. |
150 | 150 |
151 static int sigio; | 151 static int sigio; |
152 static const bool have_sigio | 152 static const bool have_sigio |
153 = octave_get_sig_number ("SIGIO", &sigio); | 153 = octave_get_sig_number ("SIGIO", &sigio); |
154 | 154 |
155 static int siglost; | 155 static int siglost; |
156 static const bool have_siglost | 156 static const bool have_siglost |
157 = octave_get_sig_number ("SIGLOST", &siglost); | 157 = octave_get_sig_number ("SIGLOST", &siglost); |
158 | 158 |
159 static int sigpipe; | 159 static int sigpipe; |
160 static const bool have_sigpipe | 160 static const bool have_sigpipe |
161 = octave_get_sig_number ("SIGPIPE", &sigpipe); | 161 = octave_get_sig_number ("SIGPIPE", &sigpipe); |
162 | 162 |
163 // Job control signals. | 163 // Job control signals. |
164 | 164 |
165 static int sigchld; | 165 static int sigchld; |
166 static const bool have_sigchld | 166 static const bool have_sigchld |
167 = octave_get_sig_number ("SIGCHLD", &sigchld); | 167 = octave_get_sig_number ("SIGCHLD", &sigchld); |
168 | 168 |
169 static int sigcld; | 169 static int sigcld; |
170 static const bool have_sigcld | 170 static const bool have_sigcld |
171 = octave_get_sig_number ("SIGCLD", &sigcld); | 171 = octave_get_sig_number ("SIGCLD", &sigcld); |
172 | 172 |
173 // Resource limit signals. | 173 // Resource limit signals. |
174 | 174 |
175 static int sigxcpu; | 175 static int sigxcpu; |
176 static const bool have_sigxcpu | 176 static const bool have_sigxcpu |
177 = octave_get_sig_number ("SIGXCPU", &sigxcpu); | 177 = octave_get_sig_number ("SIGXCPU", &sigxcpu); |
178 | 178 |
179 static int sigxfsz; | 179 static int sigxfsz; |
180 static const bool have_sigxfsz | 180 static const bool have_sigxfsz |
181 = octave_get_sig_number ("SIGXFSZ", &sigxfsz); | 181 = octave_get_sig_number ("SIGXFSZ", &sigxfsz); |
182 | 182 |
183 // User signals. | 183 // User signals. |
184 | 184 |
185 static int sigusr1; | 185 static int sigusr1; |
186 static const bool have_sigusr1 | 186 static const bool have_sigusr1 |
187 = octave_get_sig_number ("SIGUSR1", &sigusr1); | 187 = octave_get_sig_number ("SIGUSR1", &sigusr1); |
188 | 188 |
189 static int sigusr2; | 189 static int sigusr2; |
190 static const bool have_sigusr2 | 190 static const bool have_sigusr2 |
191 = octave_get_sig_number ("SIGUSR2", &sigusr2); | 191 = octave_get_sig_number ("SIGUSR2", &sigusr2); |
192 | 192 |
193 child_list& kids = __get_child_list__ (); | 193 child_list& kids = __get_child_list__ (); |
194 | 194 |
195 for (int sig = 0; sig < octave_num_signals (); sig++) | 195 for (int sig = 0; sig < octave_num_signals (); sig++) |
196 { | 196 { |
197 if (signals_caught[sig]) | 197 if (signals_caught[sig]) |
198 { | 198 { |
199 signals_caught[sig] = false; | 199 signals_caught[sig] = false; |
200 | 200 |
201 if ((have_sigchld && sig == sigchld) | 201 if ((have_sigchld && sig == sigchld) |
202 || (have_sigcld && sig == sigcld)) | 202 || (have_sigcld && sig == sigcld)) |
203 { | 203 { |
204 // FIXME: should we block or ignore? | 204 // FIXME: should we block or ignore? |
205 volatile interrupt_handler saved_interrupt_handler | 205 volatile interrupt_handler saved_interrupt_handler |
206 = ignore_interrupts (); | 206 = ignore_interrupts (); |
207 | 207 |
208 void *context = octave_block_child (); | 208 void *context = octave_block_child (); |
209 | 209 |
210 kids.wait (); | 210 kids.wait (); |
211 | 211 |
212 set_interrupt_handler (saved_interrupt_handler); | 212 set_interrupt_handler (saved_interrupt_handler); |
213 | 213 |
214 octave_unblock_child (context); | 214 octave_unblock_child (context); |
215 | 215 |
216 kids.reap (); | 216 kids.reap (); |
217 } | 217 } |
218 else if (have_sigpipe && sig == sigpipe) | 218 else if (have_sigpipe && sig == sigpipe) |
219 { | 219 { |
220 std::cerr << "warning: broken pipe" << std::endl; | 220 std::cerr << "warning: broken pipe" << std::endl; |
221 | 221 |
222 // Don't loop forever on account of this. | 222 // Don't loop forever on account of this. |
223 // FIXME: is this really needed? Does it do anything | 223 // FIXME: is this really needed? Does it do anything |
224 // useful now? | 224 // useful now? |
225 | 225 |
226 if (pipe_handler_error_count++ > 100 | 226 if (pipe_handler_error_count++ > 100 |
227 && octave_interrupt_state >= 0) | 227 && octave_interrupt_state >= 0) |
228 octave_interrupt_state++; | 228 octave_interrupt_state++; |
229 } | 229 } |
230 else if (have_sighup && sig == sighup) | 230 else if (have_sighup && sig == sighup) |
231 my_friendly_exit (sighup, Vsighup_dumps_octave_core); | 231 my_friendly_exit (sighup, Vsighup_dumps_octave_core); |
232 else if (have_sigquit && sig == sigquit) | 232 else if (have_sigquit && sig == sigquit) |
233 my_friendly_exit (sigquit, Vsigquit_dumps_octave_core); | 233 my_friendly_exit (sigquit, Vsigquit_dumps_octave_core); |
234 else if (have_sigterm && sig == sigterm) | 234 else if (have_sigterm && sig == sigterm) |
235 my_friendly_exit (sigterm, Vsigterm_dumps_octave_core); | 235 my_friendly_exit (sigterm, Vsigterm_dumps_octave_core); |
236 else if ((have_sigalrm && sig == sigalrm) | 236 else if ((have_sigalrm && sig == sigalrm) |
237 || (have_sigvtalrm && sig == sigvtalrm) | 237 || (have_sigvtalrm && sig == sigvtalrm) |
238 || (have_sigio && sig == sigio) | 238 || (have_sigio && sig == sigio) |
239 || (have_siglost && sig == siglost) | 239 || (have_siglost && sig == siglost) |
240 || (have_sigxcpu && sig == sigxcpu) | 240 || (have_sigxcpu && sig == sigxcpu) |
241 || (have_sigxfsz && sig == sigxfsz) | 241 || (have_sigxfsz && sig == sigxfsz) |
242 || (have_sigusr1 && sig == sigusr1) | 242 || (have_sigusr1 && sig == sigusr1) |
243 || (have_sigusr2 && sig == sigusr2)) | 243 || (have_sigusr2 && sig == sigusr2)) |
244 std::cerr << "warning: ignoring signal: " | 244 std::cerr << "warning: ignoring signal: " |
245 << octave_strsignal_wrapper (sig) | 245 << octave_strsignal_wrapper (sig) |
246 << std::endl; | 246 << std::endl; |
247 else if ((have_sigint && sig == sigint) | 247 else if ((have_sigint && sig == sigint) |
248 || (have_sigbreak && sig == sigbreak)) | 248 || (have_sigbreak && sig == sigbreak)) |
249 ; // Handled separately; do nothing. | 249 ; // Handled separately; do nothing. |
250 else | 250 else |
251 std::cerr << "warning: ignoring unexpected signal: " | 251 std::cerr << "warning: ignoring unexpected signal: " |
252 << octave_strsignal_wrapper (sig) | 252 << octave_strsignal_wrapper (sig) |
253 << std::endl; | 253 << std::endl; |
254 } | 254 } |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 sig_handler * | 258 sig_handler * |
259 set_signal_handler (int sig, sig_handler *handler, bool restart_syscalls) | 259 set_signal_handler (int sig, sig_handler *handler, bool restart_syscalls) |
260 { | 260 { |
261 return octave_set_signal_handler_internal (sig, handler, restart_syscalls); | 261 return octave_set_signal_handler_internal (sig, handler, restart_syscalls); |
262 } | 262 } |
263 | 263 |
264 sig_handler * | 264 sig_handler * |
265 set_signal_handler (const char *signame, sig_handler *handler, | 265 set_signal_handler (const char *signame, sig_handler *handler, |
266 bool restart_syscalls) | 266 bool restart_syscalls) |
267 { | 267 { |
268 return octave_set_signal_handler_by_name (signame, handler, | 268 return octave_set_signal_handler_by_name (signame, handler, |
269 restart_syscalls); | 269 restart_syscalls); |
270 } | 270 } |
271 | 271 |
272 static void | 272 static void |
273 generic_sig_handler (int sig) | 273 generic_sig_handler (int sig) |
274 { | 274 { |
275 // FIXME: this function may execute in a separate signal handler or | 275 // FIXME: this function may execute in a separate signal handler or |
276 // signal watcher thread so it should probably be more careful about | 276 // signal watcher thread so it should probably be more careful about |
277 // how it accesses global objects. | 277 // how it accesses global objects. |
278 | 278 |
279 octave_signal_caught = 1; | 279 octave_signal_caught = 1; |
280 | 280 |
281 signals_caught[sig] = true; | 281 signals_caught[sig] = true; |
282 | 282 |
283 static int sigint; | 283 static int sigint; |
284 static const bool have_sigint | 284 static const bool have_sigint |
285 = octave_get_sig_number ("SIGINT", &sigint); | 285 = octave_get_sig_number ("SIGINT", &sigint); |
286 | 286 |
287 static int sigbreak; | 287 static int sigbreak; |
288 static const bool have_sigbreak | 288 static const bool have_sigbreak |
289 = octave_get_sig_number ("SIGBREAK", &sigbreak); | 289 = octave_get_sig_number ("SIGBREAK", &sigbreak); |
290 | 290 |
291 if ((have_sigint && sig == sigint) | 291 if ((have_sigint && sig == sigint) |
292 || (have_sigbreak && sig == sigbreak)) | 292 || (have_sigbreak && sig == sigbreak)) |
293 { | 293 { |
294 if (! octave_initialized) | 294 if (! octave_initialized) |
295 exit (1); | 295 exit (1); |
296 | 296 |
297 if (can_interrupt) | 297 if (can_interrupt) |
298 { | 298 { |
299 octave_signal_caught = 1; | 299 octave_signal_caught = 1; |
300 octave_interrupt_state++; | 300 octave_interrupt_state++; |
301 } | 301 } |
302 } | 302 } |
303 } | 303 } |
304 | 304 |
305 static void | 305 static void |
306 deadly_sig_handler (int sig) | 306 deadly_sig_handler (int sig) |
307 { | 307 { |
308 std::cerr << "fatal: caught signal " | 308 std::cerr << "fatal: caught signal " |
309 << octave_strsignal_wrapper (sig) | 309 << octave_strsignal_wrapper (sig) |
310 << " -- stopping myself..." << std::endl; | 310 << " -- stopping myself..." << std::endl; |
311 | 311 |
312 octave_set_default_signal_handler (sig); | 312 octave_set_default_signal_handler (sig); |
313 | 313 |
314 octave_raise_wrapper (sig); | 314 octave_raise_wrapper (sig); |
315 } | 315 } |
316 | 316 |
317 static void | 317 static void |
318 fpe_sig_handler (int) | 318 fpe_sig_handler (int) |
319 { | 319 { |
320 // FIXME: is there something better we can do? | 320 // FIXME: is there something better we can do? |
321 | 321 |
322 std::cerr << "warning: floating point exception" << std::endl; | 322 std::cerr << "warning: floating point exception" << std::endl; |
323 } | 323 } |
324 | 324 |
325 interrupt_handler | 325 interrupt_handler |
326 catch_interrupts (void) | 326 catch_interrupts (void) |
327 { | 327 { |
328 interrupt_handler retval; | 328 interrupt_handler retval; |
329 | 329 |
330 retval.int_handler = set_signal_handler ("SIGINT", generic_sig_handler); | 330 retval.int_handler = set_signal_handler ("SIGINT", generic_sig_handler); |
331 retval.brk_handler = set_signal_handler ("SIGBREAK", generic_sig_handler); | 331 retval.brk_handler = set_signal_handler ("SIGBREAK", generic_sig_handler); |
332 | 332 |
333 return retval; | 333 return retval; |
334 } | 334 } |
335 | 335 |
336 interrupt_handler | 336 interrupt_handler |
337 ignore_interrupts (void) | 337 ignore_interrupts (void) |
338 { | 338 { |
339 interrupt_handler retval; | 339 interrupt_handler retval; |
340 | 340 |
341 retval.int_handler = set_signal_handler ("SIGINT", SIG_IGN); | 341 retval.int_handler = set_signal_handler ("SIGINT", SIG_IGN); |
342 retval.brk_handler = set_signal_handler ("SIGBREAK", SIG_IGN); | 342 retval.brk_handler = set_signal_handler ("SIGBREAK", SIG_IGN); |
343 | 343 |
344 return retval; | 344 return retval; |
345 } | 345 } |
346 | 346 |
347 interrupt_handler | 347 interrupt_handler |
348 set_interrupt_handler (const volatile interrupt_handler& h, | 348 set_interrupt_handler (const volatile interrupt_handler& h, |
349 bool restart_syscalls) | 349 bool restart_syscalls) |
350 { | 350 { |
351 interrupt_handler retval; | 351 interrupt_handler retval; |
352 | 352 |
353 retval.int_handler = set_signal_handler ("SIGINT", h.int_handler, | 353 retval.int_handler = set_signal_handler ("SIGINT", h.int_handler, |
354 restart_syscalls); | 354 restart_syscalls); |
355 | 355 |
356 retval.brk_handler = set_signal_handler ("SIGBREAK", h.brk_handler, | 356 retval.brk_handler = set_signal_handler ("SIGBREAK", h.brk_handler, |
357 restart_syscalls); | 357 restart_syscalls); |
358 | 358 |
359 return retval; | 359 return retval; |
360 } | 360 } |
361 | 361 |
362 // Install all the handlers for the signals we might care about. | 362 // Install all the handlers for the signals we might care about. |
363 | 363 |
364 void | 364 void |
365 install_signal_handlers (void) | 365 install_signal_handlers (void) |
366 { | 366 { |
367 if (! signals_caught) | 367 if (! signals_caught) |
368 signals_caught = new bool [octave_num_signals ()]; | 368 signals_caught = new bool [octave_num_signals ()]; |
369 | 369 |
370 for (int i = 0; i < octave_num_signals (); i++) | 370 for (int i = 0; i < octave_num_signals (); i++) |
371 signals_caught[i] = false; | 371 signals_caught[i] = false; |
372 | 372 |
373 // Interrupt signals. | 373 // Interrupt signals. |
374 | 374 |
375 catch_interrupts (); | 375 catch_interrupts (); |
376 | 376 |
377 // Program Error signals. These are most likely unrecoverable for | 377 // Program Error signals. These are most likely unrecoverable for |
378 // us. | 378 // us. |
379 | 379 |
380 set_signal_handler ("SIGABRT", deadly_sig_handler); | 380 set_signal_handler ("SIGABRT", deadly_sig_handler); |
381 set_signal_handler ("SIGBUS", deadly_sig_handler); | 381 set_signal_handler ("SIGBUS", deadly_sig_handler); |
382 set_signal_handler ("SIGEMT", deadly_sig_handler); | 382 set_signal_handler ("SIGEMT", deadly_sig_handler); |
383 set_signal_handler ("SIGILL", deadly_sig_handler); | 383 set_signal_handler ("SIGILL", deadly_sig_handler); |
384 // SIGIOT is normally another name for SIGABRT. | 384 // SIGIOT is normally another name for SIGABRT. |
385 set_signal_handler ("SIGIOT", deadly_sig_handler); | 385 set_signal_handler ("SIGIOT", deadly_sig_handler); |
386 set_signal_handler ("SIGSEGV", deadly_sig_handler); | 386 set_signal_handler ("SIGSEGV", deadly_sig_handler); |
387 set_signal_handler ("SIGSYS", deadly_sig_handler); | 387 set_signal_handler ("SIGSYS", deadly_sig_handler); |
388 set_signal_handler ("SIGTRAP", deadly_sig_handler); | 388 set_signal_handler ("SIGTRAP", deadly_sig_handler); |
389 | 389 |
390 // Handle SIGFPE separately. | 390 // Handle SIGFPE separately. |
391 | 391 |
392 set_signal_handler ("SIGFPE", fpe_sig_handler); | 392 set_signal_handler ("SIGFPE", fpe_sig_handler); |
393 | 393 |
394 // Handle other signals for which the default action is to terminate | 394 // Handle other signals for which the default action is to terminate |
395 // the program. | 395 // the program. |
396 | 396 |
397 // Termination signals. | 397 // Termination signals. |
398 | 398 |
399 set_signal_handler ("SIGHUP", generic_sig_handler); | 399 set_signal_handler ("SIGHUP", generic_sig_handler); |
400 set_signal_handler ("SIGQUIT", generic_sig_handler); | 400 set_signal_handler ("SIGQUIT", generic_sig_handler); |
401 set_signal_handler ("SIGTERM", generic_sig_handler); | 401 set_signal_handler ("SIGTERM", generic_sig_handler); |
402 | 402 |
403 // Alarm signals. | 403 // Alarm signals. |
404 | 404 |
405 set_signal_handler ("SIGALRM", generic_sig_handler); | 405 set_signal_handler ("SIGALRM", generic_sig_handler); |
406 set_signal_handler ("SIGVTALRM", generic_sig_handler); | 406 set_signal_handler ("SIGVTALRM", generic_sig_handler); |
407 | 407 |
408 // I/O signals. | 408 // I/O signals. |
409 | 409 |
410 set_signal_handler ("SIGLOST", generic_sig_handler); | 410 set_signal_handler ("SIGLOST", generic_sig_handler); |
411 set_signal_handler ("SIGPIPE", generic_sig_handler); | 411 set_signal_handler ("SIGPIPE", generic_sig_handler); |
412 | 412 |
413 // Job control signals. We only recognize signals about child | 413 // Job control signals. We only recognize signals about child |
414 // processes. | 414 // processes. |
415 | 415 |
416 set_signal_handler ("SIGCHLD", generic_sig_handler); | 416 set_signal_handler ("SIGCHLD", generic_sig_handler); |
417 set_signal_handler ("SIGCLD", generic_sig_handler); | 417 set_signal_handler ("SIGCLD", generic_sig_handler); |
418 | 418 |
419 // Resource limit signals. | 419 // Resource limit signals. |
420 | 420 |
421 // FIXME: does it really make sense to try to handle the CPU limit | 421 // FIXME: does it really make sense to try to handle the CPU limit |
422 // signal? | 422 // signal? |
423 | 423 |
424 set_signal_handler ("SIGXCPU", generic_sig_handler); | 424 set_signal_handler ("SIGXCPU", generic_sig_handler); |
425 set_signal_handler ("SIGXFSZ", generic_sig_handler); | 425 set_signal_handler ("SIGXFSZ", generic_sig_handler); |
426 | 426 |
427 // User signals. | 427 // User signals. |
428 | 428 |
429 set_signal_handler ("SIGUSR1", generic_sig_handler); | 429 set_signal_handler ("SIGUSR1", generic_sig_handler); |
430 set_signal_handler ("SIGUSR2", generic_sig_handler); | 430 set_signal_handler ("SIGUSR2", generic_sig_handler); |
431 | 431 |
432 // This does nothing on Windows systems. | 432 // This does nothing on Windows systems. |
433 octave_create_interrupt_watcher_thread (generic_sig_handler); | 433 octave_create_interrupt_watcher_thread (generic_sig_handler); |
434 } | 434 } |
435 | 435 |
436 static void | 436 static void |
437 set_sig_struct_field (octave_scalar_map& m, const char *signame) | 437 set_sig_struct_field (octave_scalar_map& m, const char *signame) |
438 { | 438 { |
439 int signum; | 439 int signum; |
440 | 440 |
441 // The names in the struct do not include the leading "SIG" prefix. | 441 // The names in the struct do not include the leading "SIG" prefix. |
442 | 442 |
443 if (octave_get_sig_number (signame, &signum)) | 443 if (octave_get_sig_number (signame, &signum)) |
444 m.assign (&signame[3], signum); | 444 m.assign (&signame[3], signum); |
445 } | 445 } |
446 | 446 |
447 static octave_scalar_map | 447 static octave_scalar_map |
448 make_sig_struct (void) | 448 make_sig_struct (void) |
449 { | 449 { |
450 octave_scalar_map m; | 450 octave_scalar_map m; |
451 | 451 |
452 set_sig_struct_field (m, "SIGABRT"); | 452 set_sig_struct_field (m, "SIGABRT"); |
453 set_sig_struct_field (m, "SIGALRM"); | 453 set_sig_struct_field (m, "SIGALRM"); |
454 set_sig_struct_field (m, "SIGBUS"); | 454 set_sig_struct_field (m, "SIGBUS"); |
455 set_sig_struct_field (m, "SIGCHLD"); | 455 set_sig_struct_field (m, "SIGCHLD"); |
456 set_sig_struct_field (m, "SIGCLD"); | 456 set_sig_struct_field (m, "SIGCLD"); |
457 set_sig_struct_field (m, "SIGCONT"); | 457 set_sig_struct_field (m, "SIGCONT"); |
458 set_sig_struct_field (m, "SIGEMT"); | 458 set_sig_struct_field (m, "SIGEMT"); |
459 set_sig_struct_field (m, "SIGFPE"); | 459 set_sig_struct_field (m, "SIGFPE"); |
460 set_sig_struct_field (m, "SIGHUP"); | 460 set_sig_struct_field (m, "SIGHUP"); |
461 set_sig_struct_field (m, "SIGILL"); | 461 set_sig_struct_field (m, "SIGILL"); |
462 set_sig_struct_field (m, "SIGINFO"); | 462 set_sig_struct_field (m, "SIGINFO"); |
463 set_sig_struct_field (m, "SIGINT"); | 463 set_sig_struct_field (m, "SIGINT"); |
464 set_sig_struct_field (m, "SIGIO"); | 464 set_sig_struct_field (m, "SIGIO"); |
465 set_sig_struct_field (m, "SIGIOT"); | 465 set_sig_struct_field (m, "SIGIOT"); |
466 set_sig_struct_field (m, "SIGKILL"); | 466 set_sig_struct_field (m, "SIGKILL"); |
467 set_sig_struct_field (m, "SIGLOST"); | 467 set_sig_struct_field (m, "SIGLOST"); |
468 set_sig_struct_field (m, "SIGPIPE"); | 468 set_sig_struct_field (m, "SIGPIPE"); |
469 set_sig_struct_field (m, "SIGPOLL"); | 469 set_sig_struct_field (m, "SIGPOLL"); |
470 set_sig_struct_field (m, "SIGPROF"); | 470 set_sig_struct_field (m, "SIGPROF"); |
471 set_sig_struct_field (m, "SIGPWR"); | 471 set_sig_struct_field (m, "SIGPWR"); |
472 set_sig_struct_field (m, "SIGQUIT"); | 472 set_sig_struct_field (m, "SIGQUIT"); |
473 set_sig_struct_field (m, "SIGSEGV"); | 473 set_sig_struct_field (m, "SIGSEGV"); |
474 set_sig_struct_field (m, "SIGSTKFLT"); | 474 set_sig_struct_field (m, "SIGSTKFLT"); |
475 set_sig_struct_field (m, "SIGSTOP"); | 475 set_sig_struct_field (m, "SIGSTOP"); |
476 set_sig_struct_field (m, "SIGSYS"); | 476 set_sig_struct_field (m, "SIGSYS"); |
477 set_sig_struct_field (m, "SIGTERM"); | 477 set_sig_struct_field (m, "SIGTERM"); |
478 set_sig_struct_field (m, "SIGTRAP"); | 478 set_sig_struct_field (m, "SIGTRAP"); |
479 set_sig_struct_field (m, "SIGTSTP"); | 479 set_sig_struct_field (m, "SIGTSTP"); |
480 set_sig_struct_field (m, "SIGTTIN"); | 480 set_sig_struct_field (m, "SIGTTIN"); |
481 set_sig_struct_field (m, "SIGTTOU"); | 481 set_sig_struct_field (m, "SIGTTOU"); |
482 set_sig_struct_field (m, "SIGUNUSED"); | 482 set_sig_struct_field (m, "SIGUNUSED"); |
483 set_sig_struct_field (m, "SIGURG"); | 483 set_sig_struct_field (m, "SIGURG"); |
484 set_sig_struct_field (m, "SIGUSR1"); | 484 set_sig_struct_field (m, "SIGUSR1"); |
485 set_sig_struct_field (m, "SIGUSR2"); | 485 set_sig_struct_field (m, "SIGUSR2"); |
486 set_sig_struct_field (m, "SIGVTALRM"); | 486 set_sig_struct_field (m, "SIGVTALRM"); |
487 set_sig_struct_field (m, "SIGWINCH"); | 487 set_sig_struct_field (m, "SIGWINCH"); |
488 set_sig_struct_field (m, "SIGXCPU"); | 488 set_sig_struct_field (m, "SIGXCPU"); |
489 set_sig_struct_field (m, "SIGXFSZ"); | 489 set_sig_struct_field (m, "SIGXFSZ"); |
490 | 490 |
491 return m; | 491 return m; |
492 } | 492 } |
493 | 493 |
494 DEFUN (SIG, args, , | 494 DEFUN (SIG, args, , |
495 doc: /* -*- texinfo -*- | 495 doc: /* -*- texinfo -*- |
496 @deftypefn {} {@var{S} =} SIG () | 496 @deftypefn {} {@var{S} =} SIG () |
497 Return a structure containing Unix signal names and their defined values. | 497 Return a structure containing Unix signal names and their defined values. |