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
12 /* Set debugging level to 0, 1, or 2 to see no, some, all debug output. */
14 #define DPRINTF if (DEBUG_LEVEL > 0) printf
16 /* Allocate space for the global variables. */
17 message m_in
; /* the input message itself */
18 message m_out
; /* the output message used for reply */
19 int who_e
; /* caller's proc number */
20 int callnr
; /* system call number */
22 extern int errno
; /* error number set by system library */
24 /* Declare some local functions. */
25 FORWARD
_PROTOTYPE(void init_server
, (int argc
, char **argv
) );
26 FORWARD
_PROTOTYPE(void sig_handler
, (void) );
27 FORWARD
_PROTOTYPE(void exit_server
, (void) );
28 FORWARD
_PROTOTYPE(void get_work
, (void) );
29 FORWARD
_PROTOTYPE(void reply
, (int whom
, int result
) );
31 /*===========================================================================*
33 *===========================================================================*/
34 PUBLIC
int main(int argc
, char **argv
)
36 /* This is the main routine of this service. The main loop consists of
37 * three major activities: getting new work, processing the work, and
38 * sending the reply. The loop never terminates, unless a panic occurs.
43 /* Initialize the server, then go to work. */
44 init_server(argc
, argv
);
46 /* Main loop - get work and do it, forever. */
49 /* Wait for incoming message, sets 'callnr' and 'who'. */
54 printf("got SYS_SIG message\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 notify(m_in
.m_source
);
71 report("IS","warning, got illegal request from:", m_in
.m_source
);
75 /* Finally send reply message, unless disabled. */
76 if (result
!= EDONTREPLY
) {
80 return(OK
); /* shouldn't come here */
83 /*===========================================================================*
85 *===========================================================================*/
86 PRIVATE
void init_server(int argc
, char **argv
)
88 /* Initialize the information service. */
91 struct sigaction sigact
;
93 /* Install signal handler. Ask PM to transform signal into message. */
94 sigact
.sa_handler
= SIG_MESS
;
95 sigact
.sa_mask
= ~0; /* block all other signals */
96 sigact
.sa_flags
= 0; /* default behaviour */
97 if (sigaction(SIGTERM
, &sigact
, NULL
) < 0)
98 report("IS","warning, sigaction() failed", errno
);
100 /* Set key mappings. IS takes all of F1-F12 and Shift+F1-F6. */
102 for (i
=1; i
<=12; i
++) bit_set(fkeys
, i
);
103 for (i
=1; i
<= 8; i
++) bit_set(sfkeys
, i
);
104 if ((s
=fkey_map(&fkeys
, &sfkeys
)) != OK
)
105 report("IS", "warning, fkey_map failed:", s
);
108 /*===========================================================================*
110 *===========================================================================*/
111 PRIVATE
void sig_handler()
116 /* Try to obtain signal set from PM. */
117 if (getsigset(&sigset
) != 0) return;
119 /* Check for known signals. */
120 if (sigismember(&sigset
, SIGTERM
)) {
125 /*===========================================================================*
127 *===========================================================================*/
128 PRIVATE
void exit_server()
130 /* Shut down the information service. */
134 /* Release the function key mappings requested in init_server().
135 * IS took all of F1-F12 and Shift+F1-F6.
138 for (i
=1; i
<=12; i
++) bit_set(fkeys
, i
);
139 for (i
=1; i
<= 7; i
++) bit_set(sfkeys
, i
);
140 if ((s
=fkey_unmap(&fkeys
, &sfkeys
)) != OK
)
141 report("IS", "warning, unfkey_map failed:", s
);
143 /* Done. Now exit. */
147 /*===========================================================================*
149 *===========================================================================*/
150 PRIVATE
void get_work()
153 status
= receive(ANY
, &m_in
); /* this blocks until message arrives */
155 panic("IS","failed to receive message!", status
);
156 who_e
= m_in
.m_source
; /* message arrived! set sender */
157 callnr
= m_in
.m_type
; /* set function call number */
160 /*===========================================================================*
162 *===========================================================================*/
163 PRIVATE
void reply(who
, result
)
164 int who
; /* destination */
165 int result
; /* report result to replyee */
168 m_out
.m_type
= result
; /* build reply message */
169 send_status
= send(who
, &m_out
); /* send the message */
170 if (OK
!= send_status
)
171 panic("IS", "unable to send reply!", send_status
);