FreeBSD/Linux Kernel Cross Reference
sys/servers/is/main.c
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; /* caller's proc number */
20 int callnr; /* system call number */
21 int sys_panic; /* flag to indicate system-wide panic */
22
23 extern int errno; /* error number set by system library */
24
25 /* Declare some local functions. */
26 FORWARD _PROTOTYPE(void init_server, (int argc, char **argv) );
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 sigset = (sigset_t) m_in.NOTIFY_ARG;
55 if (sigismember(&sigset,SIGTERM) || sigismember(&sigset,SIGKSTOP)) {
56 exit_server();
57 }
58 continue;
59 case PANIC_DUMPS:
60 printf("Oops ... panic in %d. ", who);
61 printf("Hit F-keys for debug dumps or F12 to shut down.\n");
62 sys_panic = TRUE; /* set flag to allow exit */
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, 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 * exit_server *
110 *===========================================================================*/
111 PRIVATE void exit_server()
112 {
113 /* Shut down the information service. */
114 int fkeys, sfkeys;
115 int i,s;
116
117 /* Release the function key mappings requested in init_server().
118 * IS took all of F1-F12 and Shift+F1-F6.
119 */
120 fkeys = sfkeys = 0;
121 for (i=1; i<=12; i++) bit_set(fkeys, i);
122 for (i=1; i<= 7; i++) bit_set(sfkeys, i);
123 fkey_unmap(&fkeys, &sfkeys);
124
125 /* Done. Now exit. */
126 exit(0);
127 }
128
129 /*===========================================================================*
130 * get_work *
131 *===========================================================================*/
132 PRIVATE void get_work()
133 {
134 int status = 0;
135 status = receive(ANY, &m_in); /* this blocks until message arrives */
136 if (OK != status)
137 panic("IS","failed to receive message!", status);
138 who = m_in.m_source; /* message arrived! set sender */
139 callnr = m_in.m_type; /* set function call number */
140 }
141
142 /*===========================================================================*
143 * reply *
144 *===========================================================================*/
145 PRIVATE void reply(who, result)
146 int who; /* destination */
147 int result; /* report result to replyee */
148 {
149 int send_status;
150 m_out.m_type = result; /* build reply message */
151 send_status = send(who, &m_out); /* send the message */
152 if (OK != send_status)
153 panic("IS", "unable to send reply!", send_status);
154 }
155
Cache object: 72ac57a880af63c255bd7dacd388d81b
|