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