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.
|
---|
5 | *
|
---|
6 | * Created:
|
---|
7 | * Apr 29, 2004 by Jorrit N. Herder
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "inc.h"
|
---|
11 |
|
---|
12 | /* Set debugging level to 0, 1, or 2 to see no, some, all debug output. */
|
---|
13 | #define DEBUG_LEVEL 1
|
---|
14 | #define DPRINTF if (DEBUG_LEVEL > 0) printf
|
---|
15 |
|
---|
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 */
|
---|
21 |
|
---|
22 | extern int errno; /* error number set by system library */
|
---|
23 |
|
---|
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) );
|
---|
30 |
|
---|
31 | /*===========================================================================*
|
---|
32 | * main *
|
---|
33 | *===========================================================================*/
|
---|
34 | PUBLIC int main(int argc, char **argv)
|
---|
35 | {
|
---|
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.
|
---|
39 | */
|
---|
40 | int result;
|
---|
41 | sigset_t sigset;
|
---|
42 |
|
---|
43 | /* Initialize the server, then go to work. */
|
---|
44 | init_server(argc, argv);
|
---|
45 |
|
---|
46 | /* Main loop - get work and do it, forever. */
|
---|
47 | while (TRUE) {
|
---|
48 |
|
---|
49 | /* Wait for incoming message, sets 'callnr' and 'who'. */
|
---|
50 | get_work();
|
---|
51 |
|
---|
52 | switch (callnr) {
|
---|
53 | case SYS_SIG:
|
---|
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);
|
---|
59 | }
|
---|
60 | continue;
|
---|
61 | case PROC_EVENT:
|
---|
62 | sig_handler();
|
---|
63 | continue;
|
---|
64 | case FKEY_PRESSED:
|
---|
65 | result = do_fkey_pressed(&m_in);
|
---|
66 | break;
|
---|
67 | case DEV_PING:
|
---|
68 | notify(m_in.m_source);
|
---|
69 | continue;
|
---|
70 | default:
|
---|
71 | report("IS","warning, got illegal request from:", m_in.m_source);
|
---|
72 | result = EINVAL;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /* Finally send reply message, unless disabled. */
|
---|
76 | if (result != EDONTREPLY) {
|
---|
77 | reply(who_e, result);
|
---|
78 | }
|
---|
79 | }
|
---|
80 | return(OK); /* shouldn't come here */
|
---|
81 | }
|
---|
82 |
|
---|
83 | /*===========================================================================*
|
---|
84 | * init_server *
|
---|
85 | *===========================================================================*/
|
---|
86 | PRIVATE void init_server(int argc, char **argv)
|
---|
87 | {
|
---|
88 | /* Initialize the information service. */
|
---|
89 | int fkeys, sfkeys;
|
---|
90 | int i, s;
|
---|
91 | struct sigaction sigact;
|
---|
92 |
|
---|
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);
|
---|
99 |
|
---|
100 | /* Set key mappings. IS takes all of F1-F12 and Shift+F1-F6. */
|
---|
101 | fkeys = sfkeys = 0;
|
---|
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);
|
---|
106 | }
|
---|
107 |
|
---|
108 | /*===========================================================================*
|
---|
109 | * sig_handler *
|
---|
110 | *===========================================================================*/
|
---|
111 | PRIVATE void sig_handler()
|
---|
112 | {
|
---|
113 | sigset_t sigset;
|
---|
114 | int sig;
|
---|
115 |
|
---|
116 | /* Try to obtain signal set from PM. */
|
---|
117 | if (getsigset(&sigset) != 0) return;
|
---|
118 |
|
---|
119 | /* Check for known signals. */
|
---|
120 | if (sigismember(&sigset, SIGTERM)) {
|
---|
121 | exit_server();
|
---|
122 | }
|
---|
123 | }
|
---|
124 |
|
---|
125 | /*===========================================================================*
|
---|
126 | * exit_server *
|
---|
127 | *===========================================================================*/
|
---|
128 | PRIVATE void exit_server()
|
---|
129 | {
|
---|
130 | /* Shut down the information service. */
|
---|
131 | int fkeys, sfkeys;
|
---|
132 | int i,s;
|
---|
133 |
|
---|
134 | /* Release the function key mappings requested in init_server().
|
---|
135 | * IS took all of F1-F12 and Shift+F1-F6.
|
---|
136 | */
|
---|
137 | fkeys = sfkeys = 0;
|
---|
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);
|
---|
142 |
|
---|
143 | /* Done. Now exit. */
|
---|
144 | exit(0);
|
---|
145 | }
|
---|
146 |
|
---|
147 | /*===========================================================================*
|
---|
148 | * get_work *
|
---|
149 | *===========================================================================*/
|
---|
150 | PRIVATE void get_work()
|
---|
151 | {
|
---|
152 | int status = 0;
|
---|
153 | status = receive(ANY, &m_in); /* this blocks until message arrives */
|
---|
154 | if (OK != status)
|
---|
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 */
|
---|
158 | }
|
---|
159 |
|
---|
160 | /*===========================================================================*
|
---|
161 | * reply *
|
---|
162 | *===========================================================================*/
|
---|
163 | PRIVATE void reply(who, result)
|
---|
164 | int who; /* destination */
|
---|
165 | int result; /* report result to replyee */
|
---|
166 | {
|
---|
167 | int send_status;
|
---|
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);
|
---|
172 | }
|
---|
173 |
|
---|