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 |
2214
|
106 // extern void ignore_sigchld (void); |
|
107 |
2209
|
108 // Maybe this should be in a separate file? |
|
109 |
|
110 class |
|
111 octave_child |
|
112 { |
|
113 public: |
|
114 |
|
115 typedef void (*dead_child_handler) (pid_t, int); |
|
116 |
|
117 octave_child (pid_t id = -1, dead_child_handler f = 0) |
|
118 : pid (id), handler (f) { } |
|
119 |
|
120 octave_child (const octave_child& oc) |
|
121 : pid (oc.pid), handler (oc.handler) { } |
|
122 |
|
123 octave_child& operator = (const octave_child& oc) |
|
124 { |
|
125 if (&oc != this) |
|
126 { |
|
127 pid = oc.pid; |
|
128 handler = oc.handler; |
|
129 } |
|
130 return *this; |
|
131 } |
|
132 |
|
133 ~octave_child (void) { } |
|
134 |
|
135 // The process id of this child. |
|
136 pid_t pid; |
|
137 |
|
138 // The function we call if this child dies. |
|
139 dead_child_handler handler; |
|
140 }; |
|
141 |
|
142 class |
|
143 octave_child_list |
|
144 { |
|
145 protected: |
|
146 |
|
147 octave_child_list (void) : list (0), curr_len (0) { } |
|
148 |
|
149 public: |
|
150 |
5128
|
151 ~octave_child_list (void); |
2209
|
152 |
2926
|
153 static bool instance_ok (void); |
|
154 |
2209
|
155 static void insert (pid_t pid, octave_child::dead_child_handler f); |
|
156 |
2214
|
157 static void remove (pid_t pid); |
|
158 |
2926
|
159 static int length (void); |
2209
|
160 |
2926
|
161 static octave_child& elem (int i); |
2209
|
162 |
|
163 private: |
|
164 |
|
165 Array<octave_child> list; |
|
166 |
|
167 int curr_len; |
|
168 |
|
169 static octave_child_list *instance; |
|
170 |
|
171 void do_insert (pid_t pid, octave_child::dead_child_handler f); |
2214
|
172 |
|
173 void do_remove (pid_t pid); |
2926
|
174 |
|
175 int do_length (void) const; |
|
176 |
|
177 octave_child& do_elem (int i); |
2209
|
178 }; |
|
179 |
1
|
180 #endif |
|
181 |
|
182 /* |
|
183 ;;; Local Variables: *** |
|
184 ;;; mode: C++ *** |
|
185 ;;; End: *** |
|
186 */ |