4 #include <minix/sysutil.h>
6 /* SEF Signal callbacks. */
7 static struct sef_cbs
{
8 sef_cb_signal_handler_t sef_cb_signal_handler
;
9 sef_cb_signal_manager_t sef_cb_signal_manager
;
11 SEF_CB_SIGNAL_HANDLER_DEFAULT
,
12 SEF_CB_SIGNAL_MANAGER_DEFAULT
15 /* SEF Signal prototypes for sef_receive(). */
16 int do_sef_signal_request(message
*m_ptr
);
19 EXTERN
char* sef_debug_header(void);
21 /* Information about SELF. */
22 EXTERN endpoint_t sef_self_endpoint
;
24 /*===========================================================================*
25 * process_sigmgr_signals *
26 *===========================================================================*/
27 static void process_sigmgr_signals(void)
29 /* A signal manager has pending signals in the kernel. Process them. */
35 /* Get an arbitrary pending signal. */
36 if((r
=sys_getksig(&target
, &sigset
)) != OK
)
37 panic("SEF: sys_getksig failed: %d", r
);
40 /* Stop if there are no more pending signals. */
43 /* Process every signal in the signal set. */
45 for (signo
= SIGS_FIRST
; signo
<= SIGS_LAST
; signo
++) {
46 int s
= sigismember(&sigset
, signo
);
49 /* Let the callback code process the signal. */
50 r
= sef_cbs
.sef_cb_signal_manager(target
, signo
);
52 /* Stop if process is gone. */
53 if(r
== EDEADSRCDST
) {
58 /* Tell the kernel we are done if the target is still alive. */
60 if((r
=sys_endksig(target
)) != OK
)
61 panic("SEF: sys_endksig failed :%d", r
);
67 /*===========================================================================*
68 * process_sigmgr_self_signals *
69 *===========================================================================*/
70 static void process_sigmgr_self_signals(sigset_t sigset
)
72 /* A signal manager has pending signals for itself. Process them. */
75 for (signo
= SIGS_FIRST
; signo
<= SIGS_LAST
; signo
++) {
76 int s
= sigismember(&sigset
, signo
);
79 /* Let the callback code process the signal. */
80 sef_cbs
.sef_cb_signal_handler(signo
);
85 /*===========================================================================*
86 * do_sef_signal_request *
87 *===========================================================================*/
88 int do_sef_signal_request(message
*m_ptr
)
90 /* Handle a SEF Signal request. */
94 if(m_ptr
->m_source
== SYSTEM
) {
95 /* Handle kernel signals. */
96 sigset
= m_ptr
->m_notify
.sigset
;
97 for (signo
= SIGK_FIRST
; signo
<= SIGK_LAST
; signo
++) {
98 int s
= sigismember(&sigset
, signo
);
101 /* Let the callback code handle the kernel signal. */
102 sef_cbs
.sef_cb_signal_handler(signo
);
104 /* Handle SIGKSIG for a signal manager. */
105 if(signo
== SIGKSIG
) {
106 process_sigmgr_signals();
108 /* Handle SIGKSIGSM for a signal manager. */
109 else if(signo
== SIGKSIGSM
) {
110 process_sigmgr_self_signals(sigset
);
116 /* Handle system signals from a signal manager. */
117 signo
= m_ptr
->SIGS_SIG_NUM
;
121 sef_signal_debug_begin();
122 sef_signal_dprint("%s. Got a SEF Signal request for signal %d! About to handle signal.\n",
123 sef_debug_header(), signo
);
124 sef_signal_debug_end();
127 /* Let the callback code handle the signal. */
128 sef_cbs
.sef_cb_signal_handler(signo
);
131 /* Return OK not to let anybody else intercept the request. */
135 /*===========================================================================*
136 * sef_setcb_signal_handler *
137 *===========================================================================*/
138 void sef_setcb_signal_handler(sef_cb_signal_handler_t cb
)
141 sef_cbs
.sef_cb_signal_handler
= cb
;
144 /*===========================================================================*
145 * sef_setcb_signal_manager *
146 *===========================================================================*/
147 void sef_setcb_signal_manager(sef_cb_signal_manager_t cb
)
150 sef_cbs
.sef_cb_signal_manager
= cb
;
153 /*===========================================================================*
154 * sef_cb_signal_handler_null *
155 *===========================================================================*/
156 void sef_cb_signal_handler_null(int signo
)
160 /*===========================================================================*
161 * sef_cb_signal_manager_null *
162 *===========================================================================*/
163 int sef_cb_signal_manager_null(endpoint_t target
, int signo
)
168 /*===========================================================================*
169 * sef_cb_signal_handler_term *
170 *===========================================================================*/
171 void sef_cb_signal_handler_term(int signo
)
173 /* Terminate in case of SIGTERM, ignore other signals. */
174 if(signo
== SIGTERM
) {
179 /*===========================================================================*
180 * sef_cb_signal_handler_posix_default *
181 *===========================================================================*/
182 void sef_cb_signal_handler_posix_default(int signo
)
185 /* Ignore when possible. */
194 /* Terminate in any other case unless it is a kernel signal. */
196 if(!IS_SIGK(signo
)) {