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