00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #if !defined (octave_sighandlers_h)
00035 #define octave_sighandlers_h 1
00036
00037
00038
00039
00040 #include <signal.h>
00041
00042 #include "syswait.h"
00043 #include "siglist.h"
00044
00045 #include "base-list.h"
00046
00047
00048 #ifndef RETSIGTYPE
00049 #define RETSIGTYPE void
00050 #endif
00051 #ifndef BADSIG
00052 #define BADSIG (RETSIGTYPE (*)(int))-1
00053 #endif
00054
00055 #define BLOCK_SIGNAL(sig, nvar, ovar) \
00056 do \
00057 { \
00058 sigemptyset (&nvar); \
00059 sigaddset (&nvar, sig); \
00060 sigemptyset (&ovar); \
00061 sigprocmask (SIG_BLOCK, &nvar, &ovar); \
00062 } \
00063 while (0)
00064
00065 #if !defined (SIGCHLD) && defined (SIGCLD)
00066 #define SIGCHLD SIGCLD
00067 #endif
00068
00069 #if defined (HAVE_POSIX_SIGNALS)
00070 #define BLOCK_CHILD(nvar, ovar) BLOCK_SIGNAL (SIGCHLD, nvar, ovar)
00071 #define UNBLOCK_CHILD(ovar) sigprocmask (SIG_SETMASK, &ovar, 0)
00072 #else
00073 #define BLOCK_CHILD(nvar, ovar) ovar = sigblock (sigmask (SIGCHLD))
00074 #define UNBLOCK_CHILD(ovar) sigsetmask (ovar)
00075 #endif
00076
00077 typedef RETSIGTYPE sig_handler (int);
00078
00079
00080
00081 struct
00082 octave_interrupt_handler
00083 {
00084 #ifdef SIGINT
00085 sig_handler *int_handler;
00086 #endif
00087
00088 #ifdef SIGBREAK
00089 sig_handler *brk_handler;
00090 #endif
00091 };
00092
00093
00094
00095 extern int pipe_handler_error_count;
00096
00097
00098 extern OCTINTERP_API bool can_interrupt;
00099
00100 extern OCTINTERP_API sig_handler *octave_set_signal_handler (int, sig_handler *,
00101 bool restart_syscalls = true);
00102
00103 extern OCTINTERP_API void install_signal_handlers (void);
00104
00105 extern OCTINTERP_API void octave_signal_handler (void);
00106
00107 extern OCTINTERP_API octave_interrupt_handler octave_catch_interrupts (void);
00108
00109 extern OCTINTERP_API octave_interrupt_handler octave_ignore_interrupts (void);
00110
00111 extern OCTINTERP_API octave_interrupt_handler
00112 octave_set_interrupt_handler (const volatile octave_interrupt_handler&,
00113 bool restart_syscalls = true);
00114
00115
00116
00117
00118
00119 class
00120 OCTINTERP_API
00121 octave_child
00122 {
00123 public:
00124
00125
00126
00127
00128
00129
00130
00131 typedef bool (*child_event_handler) (pid_t, int);
00132
00133 octave_child (pid_t id = -1, child_event_handler f = 0)
00134 : pid (id), handler (f), have_status (0), status (0) { }
00135
00136 octave_child (const octave_child& oc)
00137 : pid (oc.pid), handler (oc.handler),
00138 have_status (oc.have_status), status (oc.status) { }
00139
00140 octave_child& operator = (const octave_child& oc)
00141 {
00142 if (&oc != this)
00143 {
00144 pid = oc.pid;
00145 handler = oc.handler;
00146 have_status = oc.have_status;
00147 status = oc.status;
00148 }
00149 return *this;
00150 }
00151
00152 ~octave_child (void) { }
00153
00154
00155 pid_t pid;
00156
00157
00158 child_event_handler handler;
00159
00160
00161 sig_atomic_t have_status;
00162
00163
00164
00165 int status;
00166 };
00167
00168 class
00169 OCTINTERP_API
00170 octave_child_list
00171 {
00172 protected:
00173
00174 octave_child_list (void) { }
00175
00176 class octave_child_list_rep : public octave_base_list<octave_child>
00177 {
00178 public:
00179
00180 void insert (pid_t pid, octave_child::child_event_handler f);
00181
00182 void reap (void);
00183
00184 bool wait (void);
00185 };
00186
00187 public:
00188
00189 ~octave_child_list (void) { }
00190
00191 static void insert (pid_t pid, octave_child::child_event_handler f);
00192
00193 static void reap (void);
00194
00195 static bool wait (void);
00196
00197 static void remove (pid_t pid);
00198
00199 private:
00200
00201 static bool instance_ok (void);
00202
00203 static octave_child_list_rep *instance;
00204 };
00205
00206 #endif
00207
00208
00209
00210
00211
00212