1
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 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 |
|
40 typedef RETSIGTYPE sig_handler (int); |
|
41 |
2554
|
42 // All we need to do is declare pointers to this, so we don't need to |
|
43 // have the whole declaration here. |
|
44 |
|
45 struct octave_interrupt_handler; |
|
46 |
1
|
47 // Nonzero means we have already printed a message for this series of |
|
48 // SIGPIPES. We assume that the writer will eventually give up. |
|
49 extern int pipe_handler_error_count; |
|
50 |
|
51 // Nonzero means we can be interrupted. |
|
52 extern int can_interrupt; |
|
53 |
1443
|
54 extern sig_handler *octave_set_signal_handler (int, sig_handler *); |
|
55 |
1
|
56 extern void install_signal_handlers (void); |
|
57 |
2554
|
58 extern void octave_catch_interrupts (void); |
|
59 |
|
60 extern octave_interrupt_handler *octave_ignore_interrupts (void); |
|
61 |
|
62 extern octave_interrupt_handler * |
|
63 octave_set_interrupt_handler (const volatile octave_interrupt_handler *); |
1651
|
64 |
2016
|
65 extern void octave_save_signal_mask (void); |
|
66 |
|
67 extern void octave_restore_signal_mask (void); |
|
68 |
2214
|
69 // extern void ignore_sigchld (void); |
|
70 |
834
|
71 // This is taken directly from Emacs 19: |
|
72 |
839
|
73 #ifndef SYS_SIGLIST_DECLARED |
|
74 extern char *sys_siglist[]; |
834
|
75 #endif |
|
76 |
2209
|
77 // Maybe this should be in a separate file? |
|
78 |
|
79 class |
|
80 octave_child |
|
81 { |
|
82 public: |
|
83 |
|
84 typedef void (*dead_child_handler) (pid_t, int); |
|
85 |
|
86 octave_child (pid_t id = -1, dead_child_handler f = 0) |
|
87 : pid (id), handler (f) { } |
|
88 |
|
89 octave_child (const octave_child& oc) |
|
90 : pid (oc.pid), handler (oc.handler) { } |
|
91 |
|
92 octave_child& operator = (const octave_child& oc) |
|
93 { |
|
94 if (&oc != this) |
|
95 { |
|
96 pid = oc.pid; |
|
97 handler = oc.handler; |
|
98 } |
|
99 return *this; |
|
100 } |
|
101 |
|
102 ~octave_child (void) { } |
|
103 |
|
104 // The process id of this child. |
|
105 pid_t pid; |
|
106 |
|
107 // The function we call if this child dies. |
|
108 dead_child_handler handler; |
|
109 }; |
|
110 |
|
111 class |
|
112 octave_child_list |
|
113 { |
|
114 protected: |
|
115 |
|
116 octave_child_list (void) : list (0), curr_len (0) { } |
|
117 |
|
118 public: |
|
119 |
|
120 ~octave_child_list (void) { } |
|
121 |
|
122 static void insert (pid_t pid, octave_child::dead_child_handler f); |
|
123 |
2214
|
124 static void remove (pid_t pid); |
|
125 |
2209
|
126 static int length (void) { return instance ? instance->curr_len : 0; } |
|
127 |
|
128 static octave_child& elem (int i) |
|
129 { |
|
130 static octave_child foo; |
|
131 |
|
132 if (instance) |
|
133 { |
|
134 int n = length (); |
|
135 |
|
136 if (i >= 0 && i < n) |
|
137 return instance->list (i); |
|
138 } |
|
139 |
|
140 return foo; |
|
141 } |
|
142 |
|
143 private: |
|
144 |
|
145 Array<octave_child> list; |
|
146 |
|
147 int curr_len; |
|
148 |
|
149 static octave_child_list *instance; |
|
150 |
|
151 void do_insert (pid_t pid, octave_child::dead_child_handler f); |
2214
|
152 |
|
153 void do_remove (pid_t pid); |
2209
|
154 }; |
|
155 |
1
|
156 #endif |
|
157 |
|
158 /* |
|
159 ;;; Local Variables: *** |
|
160 ;;; mode: C++ *** |
|
161 ;;; End: *** |
|
162 */ |