1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 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, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
2939
|
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 |
834
|
31 // This file should always be included after config.h! |
|
32 |
383
|
33 #if !defined (octave_sighandlers_h) |
|
34 #define octave_sighandlers_h 1 |
1
|
35 |
3566
|
36 // Include signal.h, not csignal since the latter might only define |
|
37 // the ANSI standard C signal interface. |
|
38 |
|
39 #include <signal.h> |
2209
|
40 |
|
41 #include "syswait.h" |
3546
|
42 #include "siglist.h" |
2209
|
43 |
3566
|
44 #include <Array.h> |
|
45 |
290
|
46 // Signal handler return type. |
|
47 #ifndef RETSIGTYPE |
|
48 #define RETSIGTYPE void |
|
49 #endif |
|
50 #ifndef BADSIG |
|
51 #define BADSIG (RETSIGTYPE (*)(int))-1 |
|
52 #endif |
|
53 |
2693
|
54 #define BLOCK_SIGNAL(sig, nvar, ovar) \ |
|
55 do \ |
|
56 { \ |
|
57 sigemptyset (&nvar); \ |
|
58 sigaddset (&nvar, sig); \ |
|
59 sigemptyset (&ovar); \ |
|
60 sigprocmask (SIG_BLOCK, &nvar, &ovar); \ |
|
61 } \ |
|
62 while (0) |
|
63 |
|
64 #if defined (HAVE_POSIX_SIGNALS) |
|
65 #define BLOCK_CHILD(nvar, ovar) BLOCK_SIGNAL (SIGCHLD, nvar, ovar) |
|
66 #define UNBLOCK_CHILD(ovar) sigprocmask (SIG_SETMASK, &ovar, 0) |
|
67 #else |
|
68 #define BLOCK_CHILD(nvar, ovar) ovar = sigblock (sigmask (SIGCHLD)) |
|
69 #define UNBLOCK_CHILD(ovar) sigsetmask (ovar) |
|
70 #endif |
|
71 |
290
|
72 typedef RETSIGTYPE sig_handler (int); |
|
73 |
2705
|
74 // XXX FIXME XXX -- the data should probably be private... |
2554
|
75 |
2705
|
76 struct |
|
77 octave_interrupt_handler |
|
78 { |
|
79 #ifdef SIGINT |
|
80 sig_handler *int_handler; |
|
81 #endif |
|
82 |
|
83 #ifdef SIGBREAK |
|
84 sig_handler *brk_handler; |
|
85 #endif |
|
86 }; |
2554
|
87 |
1
|
88 // Nonzero means we have already printed a message for this series of |
|
89 // SIGPIPES. We assume that the writer will eventually give up. |
|
90 extern int pipe_handler_error_count; |
|
91 |
3018
|
92 // TRUE means we can be interrupted. |
|
93 extern bool can_interrupt; |
1
|
94 |
1443
|
95 extern sig_handler *octave_set_signal_handler (int, sig_handler *); |
|
96 |
1
|
97 extern void install_signal_handlers (void); |
|
98 |
2705
|
99 extern octave_interrupt_handler octave_catch_interrupts (void); |
2554
|
100 |
2705
|
101 extern octave_interrupt_handler octave_ignore_interrupts (void); |
2554
|
102 |
2705
|
103 extern octave_interrupt_handler |
|
104 octave_set_interrupt_handler (const volatile octave_interrupt_handler&); |
1651
|
105 |
2016
|
106 extern void octave_save_signal_mask (void); |
|
107 |
|
108 extern void octave_restore_signal_mask (void); |
|
109 |
2214
|
110 // extern void ignore_sigchld (void); |
|
111 |
2209
|
112 // Maybe this should be in a separate file? |
|
113 |
|
114 class |
|
115 octave_child |
|
116 { |
|
117 public: |
|
118 |
|
119 typedef void (*dead_child_handler) (pid_t, int); |
|
120 |
|
121 octave_child (pid_t id = -1, dead_child_handler f = 0) |
|
122 : pid (id), handler (f) { } |
|
123 |
|
124 octave_child (const octave_child& oc) |
|
125 : pid (oc.pid), handler (oc.handler) { } |
|
126 |
|
127 octave_child& operator = (const octave_child& oc) |
|
128 { |
|
129 if (&oc != this) |
|
130 { |
|
131 pid = oc.pid; |
|
132 handler = oc.handler; |
|
133 } |
|
134 return *this; |
|
135 } |
|
136 |
|
137 ~octave_child (void) { } |
|
138 |
|
139 // The process id of this child. |
|
140 pid_t pid; |
|
141 |
|
142 // The function we call if this child dies. |
|
143 dead_child_handler handler; |
|
144 }; |
|
145 |
|
146 class |
|
147 octave_child_list |
|
148 { |
|
149 protected: |
|
150 |
|
151 octave_child_list (void) : list (0), curr_len (0) { } |
|
152 |
|
153 public: |
|
154 |
|
155 ~octave_child_list (void) { } |
|
156 |
2926
|
157 static bool instance_ok (void); |
|
158 |
2209
|
159 static void insert (pid_t pid, octave_child::dead_child_handler f); |
|
160 |
2214
|
161 static void remove (pid_t pid); |
|
162 |
2926
|
163 static int length (void); |
2209
|
164 |
2926
|
165 static octave_child& elem (int i); |
2209
|
166 |
|
167 private: |
|
168 |
|
169 Array<octave_child> list; |
|
170 |
|
171 int curr_len; |
|
172 |
|
173 static octave_child_list *instance; |
|
174 |
|
175 void do_insert (pid_t pid, octave_child::dead_child_handler f); |
2214
|
176 |
|
177 void do_remove (pid_t pid); |
2926
|
178 |
|
179 int do_length (void) const; |
|
180 |
|
181 octave_child& do_elem (int i); |
2209
|
182 }; |
|
183 |
1
|
184 #endif |
|
185 |
|
186 /* |
|
187 ;;; Local Variables: *** |
|
188 ;;; mode: C++ *** |
|
189 ;;; End: *** |
|
190 */ |