drop safemap code
[minix.git] / servers / is / main.c
blobd8fc19bf461718ab02f20fcf92be20783d19cc94
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 static message m_in; /* the input message itself */
15 static message m_out; /* the output message used for reply */
16 static endpoint_t who_e; /* caller's proc number */
17 static int callnr; /* system call number */
19 extern int errno; /* error number set by system library */
21 /* Declare some local functions. */
22 static void get_work(void);
23 static void reply(int whom, int result);
25 /* SEF functions and variables. */
26 static void sef_local_startup(void);
27 static int sef_cb_init_fresh(int type, sef_init_info_t *info);
28 static void sef_cb_signal_handler(int signo);
30 /*===========================================================================*
31 * main *
32 *===========================================================================*/
33 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;
41 /* SEF local startup. */
42 env_setargs(argc, argv);
43 sef_local_startup();
45 /* Main loop - get work and do it, forever. */
46 while (TRUE) {
47 /* Wait for incoming message, sets 'callnr' and 'who'. */
48 get_work();
50 if (is_notify(callnr)) {
51 switch (_ENDPOINT_P(who_e)) {
52 case TTY_PROC_NR:
53 result = do_fkey_pressed(&m_in);
54 break;
55 default:
56 /* FIXME: error message. */
57 result = EDONTREPLY;
58 break;
61 else {
62 printf("IS: warning, got illegal request %d from %d\n",
63 callnr, m_in.m_source);
64 result = EDONTREPLY;
67 /* Finally send reply message, unless disabled. */
68 if (result != EDONTREPLY) {
69 reply(who_e, result);
72 return(OK); /* shouldn't come here */
75 /*===========================================================================*
76 * sef_local_startup *
77 *===========================================================================*/
78 static void sef_local_startup()
80 /* Register init callbacks. */
81 sef_setcb_init_fresh(sef_cb_init_fresh);
82 sef_setcb_init_lu(sef_cb_init_fresh);
83 sef_setcb_init_restart(sef_cb_init_fresh);
85 /* Register live update callbacks. */
86 sef_setcb_lu_prepare(sef_cb_lu_prepare_always_ready);
87 sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_standard);
89 /* Register signal callbacks. */
90 sef_setcb_signal_handler(sef_cb_signal_handler);
92 /* Let SEF perform startup. */
93 sef_startup();
96 /*===========================================================================*
97 * sef_cb_init_fresh *
98 *===========================================================================*/
99 static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
101 /* Initialize the information server. */
103 /* Set key mappings. */
104 map_unmap_fkeys(TRUE /*map*/);
106 return(OK);
109 /*===========================================================================*
110 * sef_cb_signal_handler *
111 *===========================================================================*/
112 static void sef_cb_signal_handler(int signo)
114 /* Only check for termination signal, ignore anything else. */
115 if (signo != SIGTERM) return;
117 /* Shutting down. Unset key mappings, and quit. */
118 map_unmap_fkeys(FALSE /*map*/);
120 exit(0);
123 /*===========================================================================*
124 * get_work *
125 *===========================================================================*/
126 static void get_work()
128 int status = 0;
129 status = sef_receive(ANY, &m_in); /* this blocks until message arrives */
130 if (OK != status)
131 panic("sef_receive failed!: %d", status);
132 who_e = m_in.m_source; /* message arrived! set sender */
133 callnr = m_in.m_type; /* set function call number */
136 /*===========================================================================*
137 * reply *
138 *===========================================================================*/
139 static void reply(who, result)
140 int who; /* destination */
141 int result; /* report result to replyee */
143 int send_status;
144 m_out.m_type = result; /* build reply message */
145 send_status = send(who, &m_out); /* send the message */
146 if (OK != send_status)
147 panic("unable to send reply!: %d", send_status);