GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
sighandlers.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2015 John W. Eaton
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
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
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
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 /*
24 
25 The signal blocking macros defined below were adapted from similar
26 functions from GNU Bash, the Bourne Again SHell, copyright (C) 1994
27 Free Software Foundation, Inc.
28 
29 */
30 
31 // This file should always be included after config.h!
32 
33 #if !defined (octave_sighandlers_h)
34 #define octave_sighandlers_h 1
35 
36 // Include signal.h, not csignal since the latter might only define
37 // the ANSI standard C signal interface.
38 
39 #include <signal.h>
40 
41 #include "syswait.h"
42 #include "siglist.h"
43 
44 #include "base-list.h"
45 
46 typedef void sig_handler (int);
47 
48 // FIXME: the data should probably be private...
49 
50 struct
52 {
53 #ifdef SIGINT
54  sig_handler *int_handler;
55 #endif
56 
57 #ifdef SIGBREAK
58  sig_handler *brk_handler;
59 #endif
60 };
61 
62 // Nonzero means we have already printed a message for this series of
63 // SIGPIPES. We assume that the writer will eventually give up.
64 extern int pipe_handler_error_count;
65 
66 // TRUE means we can be interrupted.
67 extern OCTINTERP_API bool can_interrupt;
68 
69 extern OCTINTERP_API
71  bool restart_syscalls = true);
72 
73 extern OCTINTERP_API void install_signal_handlers (void);
74 
75 extern OCTINTERP_API void octave_signal_handler (void);
76 
78 
80 
83  bool restart_syscalls = true);
84 
85 #if defined (__WIN32__) && ! defined (__CYGWIN__)
86 extern OCTINTERP_API void w32_raise_sigint (void);
87 #endif
88 
89 // extern void ignore_sigchld (void);
90 
91 // Maybe this should be in a separate file?
92 
93 class
96 {
97 public:
98 
99  // Do whatever to handle event for child with PID (might not
100  // actually be dead, could just be stopped). Return true if
101  // the list element corresponding to PID should be removed from
102  // list. This function should not call any functions that modify
103  // the octave_child_list.
104 
105  typedef bool (*child_event_handler) (pid_t, int);
106 
107  octave_child (pid_t id = -1, child_event_handler f = 0)
108  : pid (id), handler (f), have_status (0), status (0) { }
109 
111  : pid (oc.pid), handler (oc.handler),
112  have_status (oc.have_status), status (oc.status) { }
113 
114  octave_child& operator = (const octave_child& oc)
115  {
116  if (&oc != this)
117  {
118  pid = oc.pid;
119  handler = oc.handler;
120  have_status = oc.have_status;
121  status = oc.status;
122  }
123  return *this;
124  }
125 
126  ~octave_child (void) { }
127 
128  // The process id of this child.
129  pid_t pid;
130 
131  // The function we call if an event happens for this child.
132  child_event_handler handler;
133 
134  // Nonzero if this child has stopped or terminated.
135  sig_atomic_t have_status;
136 
137  // The status of this child; 0 if running, otherwise a status value
138  // from waitpid.
139  int status;
140 };
141 
142 class
145 {
146 protected:
147 
148  octave_child_list (void) { }
149 
150  class octave_child_list_rep : public octave_base_list<octave_child>
151  {
152  public:
153 
154  void insert (pid_t pid, octave_child::child_event_handler f);
155 
156  void reap (void);
157 
158  bool wait (void);
159  };
160 
161 public:
162 
164 
165  static void insert (pid_t pid, octave_child::child_event_handler f);
166 
167  static void reap (void);
168 
169  static bool wait (void);
170 
171  static void remove (pid_t pid);
172 
173 private:
174 
175  static bool instance_ok (void);
176 
178 
179  static void cleanup_instance (void) { delete instance; instance = 0; }
180 };
181 
182 // TRUE means we should try to enter the debugger on SIGINT.
184 
185 #endif
int bool
Definition: mex.h:56
static void cleanup_instance(void)
Definition: sighandlers.h:179
OCTINTERP_API octave_interrupt_handler octave_set_interrupt_handler(const volatile octave_interrupt_handler &, bool restart_syscalls=true)
Definition: sighandlers.cc:603
octave_child(pid_t id=-1, child_event_handler f=0)
Definition: sighandlers.h:107
OCTINTERP_API octave_interrupt_handler octave_catch_interrupts(void)
Definition: sighandlers.cc:563
sig_atomic_t have_status
Definition: sighandlers.h:135
int pipe_handler_error_count
Definition: sighandlers.cc:58
OCTINTERP_API bool Vdebug_on_interrupt
Definition: sighandlers.cc:64
OCTINTERP_API void octave_signal_handler(void)
Definition: sighandlers.cc:269
OCTINTERP_API void install_signal_handlers(void)
Definition: sighandlers.cc:628
static octave_child_list_rep * instance
Definition: sighandlers.h:177
~octave_child_list(void)
Definition: sighandlers.h:163
F77_RET_T const double const double * f
#define OCTINTERP_API
Definition: mexproto.h:66
child_event_handler handler
Definition: sighandlers.h:132
octave_child(const octave_child &oc)
Definition: sighandlers.h:110
OCTINTERP_API octave_interrupt_handler octave_ignore_interrupts(void)
Definition: sighandlers.cc:583
OCTINTERP_API sig_handler * octave_set_signal_handler(int, sig_handler *, bool restart_syscalls=true)
Definition: sighandlers.cc:360
OCTINTERP_API bool can_interrupt
Definition: sighandlers.cc:61
void sig_handler(int)
Definition: sighandlers.h:46
bool(* child_event_handler)(pid_t, int)
Definition: sighandlers.h:105
~octave_child(void)
Definition: sighandlers.h:126