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