add swifi to the build/install.
[minix.git] / servers / is / main.c
blob8e0d71b07b79c35d66944e5e61eb01d5308d508f
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 */
10 #include "inc.h"
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 /*===========================================================================*
31 * main *
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.
39 int result;
40 sigset_t sigset;
42 /* SEF local startup. */
43 env_setargs(argc, argv);
44 sef_local_startup();
46 /* Main loop - get work and do it, forever. */
47 while (TRUE) {
48 /* Wait for incoming message, sets 'callnr' and 'who'. */
49 get_work();
51 if (is_notify(callnr)) {
52 switch (_ENDPOINT_P(who_e)) {
53 case SYSTEM:
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);
60 continue;
61 case PM_PROC_NR:
62 sig_handler();
63 continue;
64 case TTY_PROC_NR:
65 result = do_fkey_pressed(&m_in);
66 break;
67 default:
68 /* FIXME: error message. */
69 result = EDONTREPLY;
70 break;
73 else {
74 printf("IS: warning, got illegal request %d from %d\n",
75 callnr, m_in.m_source);
76 result = EDONTREPLY;
79 /* Finally send reply message, unless disabled. */
80 if (result != EDONTREPLY) {
81 reply(who_e, result);
84 return(OK); /* shouldn't come here */
87 /*===========================================================================*
88 * sef_local_startup *
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. */
102 sef_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*/);
123 return(OK);
126 /*===========================================================================*
127 * sig_handler *
128 *===========================================================================*/
129 PRIVATE void sig_handler()
131 sigset_t sigset;
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*/);
142 exit(0);
145 /*===========================================================================*
146 * get_work *
147 *===========================================================================*/
148 PRIVATE void get_work()
150 int status = 0;
151 status = sef_receive(ANY, &m_in); /* this blocks until message arrives */
152 if (OK != status)
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 /*===========================================================================*
159 * reply *
160 *===========================================================================*/
161 PRIVATE void reply(who, result)
162 int who; /* destination */
163 int result; /* report result to replyee */
165 int send_status;
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);