xref: /minix3/minix/servers/is/main.c (revision 4aa48abab95b2c3bef55ef84ec4b7c49368fb6f8)
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 #include <minix/endpoint.h>
12 
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 */
18 
19 /* Declare some local functions. */
20 static void get_work(void);
21 static void reply(int whom, int result);
22 
23 /* SEF functions and variables. */
24 static void sef_local_startup(void);
25 static int sef_cb_init_fresh(int type, sef_init_info_t *info);
26 static void sef_cb_signal_handler(int signo);
27 
28 /*===========================================================================*
29  *				main                                         *
30  *===========================================================================*/
main(int argc,char ** argv)31 int main(int argc, char **argv)
32 {
33 /* This is the main routine of this service. The main loop consists of
34  * three major activities: getting new work, processing the work, and
35  * sending the reply. The loop never terminates, unless a panic occurs.
36  */
37   int result;
38 
39   /* SEF local startup. */
40   env_setargs(argc, argv);
41   sef_local_startup();
42 
43   /* Main loop - get work and do it, forever. */
44   while (TRUE) {
45       /* Wait for incoming message, sets 'callnr' and 'who'. */
46       get_work();
47 
48       if (is_notify(callnr)) {
49 	      switch (_ENDPOINT_P(who_e)) {
50 		      case TTY_PROC_NR:
51 			      result = do_fkey_pressed(&m_in);
52 			      break;
53 		      default:
54 			      /* FIXME: error message. */
55 			      result = EDONTREPLY;
56 			      break;
57 	      }
58       }
59       else {
60           printf("IS: warning, got illegal request %d from %d\n",
61           	callnr, m_in.m_source);
62           result = EDONTREPLY;
63       }
64 
65       /* Finally send reply message, unless disabled. */
66       if (result != EDONTREPLY) {
67 	  reply(who_e, result);
68       }
69   }
70   return(OK);				/* shouldn't come here */
71 }
72 
73 /*===========================================================================*
74  *			       sef_local_startup			     *
75  *===========================================================================*/
76 static void
sef_local_startup(void)77 sef_local_startup(void)
78 {
79   /* Register init callbacks. */
80   sef_setcb_init_fresh(sef_cb_init_fresh);
81   sef_setcb_init_lu(sef_cb_init_fresh);
82   sef_setcb_init_restart(sef_cb_init_fresh);
83 
84   /* Register signal callbacks. */
85   sef_setcb_signal_handler(sef_cb_signal_handler);
86 
87   /* Let SEF perform startup. */
88   sef_startup();
89 }
90 
91 /*===========================================================================*
92  *		            sef_cb_init_fresh                                *
93  *===========================================================================*/
sef_cb_init_fresh(int UNUSED (type),sef_init_info_t * UNUSED (info))94 static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
95 {
96 /* Initialize the information server. */
97 
98   /* Set key mappings. */
99   map_unmap_fkeys(TRUE /*map*/);
100 
101   return(OK);
102 }
103 
104 /*===========================================================================*
105  *		            sef_cb_signal_handler                            *
106  *===========================================================================*/
sef_cb_signal_handler(int signo)107 static void sef_cb_signal_handler(int signo)
108 {
109   /* Only check for termination signal, ignore anything else. */
110   if (signo != SIGTERM) return;
111 
112   /* Shutting down. Unset key mappings, and quit. */
113   map_unmap_fkeys(FALSE /*map*/);
114 
115   exit(0);
116 }
117 
118 /*===========================================================================*
119  *				get_work                                     *
120  *===========================================================================*/
121 static void
get_work(void)122 get_work(void)
123 {
124     int status = 0;
125     status = sef_receive(ANY, &m_in);   /* this blocks until message arrives */
126     if (OK != status)
127         panic("sef_receive failed!: %d", status);
128     who_e = m_in.m_source;        /* message arrived! set sender */
129     callnr = m_in.m_type;       /* set function call number */
130 }
131 
132 /*===========================================================================*
133  *				reply					     *
134  *===========================================================================*/
135 static void
reply(int who,int result)136 reply(
137 	int who,                           	/* destination */
138 	int result                           	/* report result to replyee */
139 )
140 {
141     int send_status;
142     m_out.m_type = result;  		/* build reply message */
143     send_status = ipc_send(who, &m_out);    /* send the message */
144     if (OK != send_status)
145         panic("unable to send reply!: %d", send_status);
146 }
147 
148 
149