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