1 /* System Information Service.
2 * This service handles the various debugging dumps, such as the process
3 * table, so that these no longer directly touch kernel memory. Instead, the
4 * system task is asked to copy some table in local memory.
7 * Apr 29, 2004 by Jorrit N. Herder
11 #include <minix/endpoint.h>
13 /* Allocate space for the global variables. */
14 message m_in
; /* the input message itself */
15 message m_out
; /* the output message used for reply */
16 int who_e
; /* caller's proc number */
17 int callnr
; /* system call number */
19 extern int errno
; /* error number set by system library */
21 /* Declare some local functions. */
22 FORWARD
_PROTOTYPE(void sig_handler
, (void) );
23 FORWARD
_PROTOTYPE(void get_work
, (void) );
24 FORWARD
_PROTOTYPE(void reply
, (int whom
, int result
) );
26 /* SEF functions and variables. */
27 FORWARD
_PROTOTYPE( void sef_local_startup
, (void) );
28 FORWARD
_PROTOTYPE( int sef_cb_init_fresh
, (int type
, sef_init_info_t
*info
) );
30 /*===========================================================================*
32 *===========================================================================*/
33 PUBLIC
int main(int argc
, char **argv
)
35 /* This is the main routine of this service. The main loop consists of
36 * three major activities: getting new work, processing the work, and
37 * sending the reply. The loop never terminates, unless a panic occurs.
42 /* SEF local startup. */
43 env_setargs(argc
, argv
);
46 /* Main loop - get work and do it, forever. */
48 /* Wait for incoming message, sets 'callnr' and 'who'. */
51 if (is_notify(callnr
)) {
52 switch (_ENDPOINT_P(who_e
)) {
54 printf("got message from SYSTEM\n");
55 sigset
= m_in
.NOTIFY_ARG
;
56 for ( result
=0; result
< _NSIG
; result
++) {
57 if (sigismember(&sigset
, result
))
58 printf("signal %d found\n", result
);
65 result
= do_fkey_pressed(&m_in
);
68 /* FIXME: error message. */
74 printf("IS: warning, got illegal request %d from %d\n",
75 callnr
, m_in
.m_source
);
79 /* Finally send reply message, unless disabled. */
80 if (result
!= EDONTREPLY
) {
84 return(OK
); /* shouldn't come here */
87 /*===========================================================================*
89 *===========================================================================*/
90 PRIVATE
void sef_local_startup()
92 /* Register init callbacks. */
93 sef_setcb_init_fresh(sef_cb_init_fresh
);
94 sef_setcb_init_lu(sef_cb_init_fresh
);
95 sef_setcb_init_restart(sef_cb_init_fresh
);
97 /* Register live update callbacks. */
98 sef_setcb_lu_prepare(sef_cb_lu_prepare_always_ready
);
99 sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_standard
);
101 /* Let SEF perform startup. */
105 /*===========================================================================*
106 * sef_cb_init_fresh *
107 *===========================================================================*/
108 PRIVATE
int sef_cb_init_fresh(int type
, sef_init_info_t
*info
)
110 /* Initialize the information server. */
111 struct sigaction sigact
;
113 /* Install signal handler. Ask PM to transform signal into message. */
114 sigact
.sa_handler
= SIG_MESS
;
115 sigact
.sa_mask
= ~0; /* block all other signals */
116 sigact
.sa_flags
= 0; /* default behaviour */
117 if (sigaction(SIGTERM
, &sigact
, NULL
) < 0)
118 report("IS","warning, sigaction() failed", errno
);
120 /* Set key mappings. */
121 map_unmap_fkeys(TRUE
/*map*/);
126 /*===========================================================================*
128 *===========================================================================*/
129 PRIVATE
void sig_handler()
133 /* Try to obtain signal set from PM. */
134 if (getsigset(&sigset
) != 0) return;
136 /* Only check for termination signal. */
137 if (!sigismember(&sigset
, SIGTERM
)) return;
139 /* Shutting down. Unset key mappings, and quit. */
140 map_unmap_fkeys(FALSE
/*map*/);
145 /*===========================================================================*
147 *===========================================================================*/
148 PRIVATE
void get_work()
151 status
= sef_receive(ANY
, &m_in
); /* this blocks until message arrives */
153 panic("IS","sef_receive failed!", status
);
154 who_e
= m_in
.m_source
; /* message arrived! set sender */
155 callnr
= m_in
.m_type
; /* set function call number */
158 /*===========================================================================*
160 *===========================================================================*/
161 PRIVATE
void reply(who
, result
)
162 int who
; /* destination */
163 int result
; /* report result to replyee */
166 m_out
.m_type
= result
; /* build reply message */
167 send_status
= send(who
, &m_out
); /* send the message */
168 if (OK
!= send_status
)
169 panic("IS", "unable to send reply!", send_status
);