1433d6423SLionel Sambuc /* System Information Service.
2433d6423SLionel Sambuc * This service handles the various debugging dumps, such as the process
3433d6423SLionel Sambuc * table, so that these no longer directly touch kernel memory. Instead, the
4433d6423SLionel Sambuc * system task is asked to copy some table in local memory.
5433d6423SLionel Sambuc *
6433d6423SLionel Sambuc * Created:
7433d6423SLionel Sambuc * Apr 29, 2004 by Jorrit N. Herder
8433d6423SLionel Sambuc */
9433d6423SLionel Sambuc
10433d6423SLionel Sambuc #include "inc.h"
11433d6423SLionel Sambuc #include <minix/endpoint.h>
12433d6423SLionel Sambuc
13433d6423SLionel Sambuc /* Allocate space for the global variables. */
14433d6423SLionel Sambuc static message m_in; /* the input message itself */
15433d6423SLionel Sambuc static message m_out; /* the output message used for reply */
16433d6423SLionel Sambuc static endpoint_t who_e; /* caller's proc number */
17433d6423SLionel Sambuc static int callnr; /* system call number */
18433d6423SLionel Sambuc
19433d6423SLionel Sambuc /* Declare some local functions. */
20433d6423SLionel Sambuc static void get_work(void);
21433d6423SLionel Sambuc static void reply(int whom, int result);
22433d6423SLionel Sambuc
23433d6423SLionel Sambuc /* SEF functions and variables. */
24433d6423SLionel Sambuc static void sef_local_startup(void);
25433d6423SLionel Sambuc static int sef_cb_init_fresh(int type, sef_init_info_t *info);
26433d6423SLionel Sambuc static void sef_cb_signal_handler(int signo);
27433d6423SLionel Sambuc
28433d6423SLionel Sambuc /*===========================================================================*
29433d6423SLionel Sambuc * main *
30433d6423SLionel Sambuc *===========================================================================*/
main(int argc,char ** argv)31433d6423SLionel Sambuc int main(int argc, char **argv)
32433d6423SLionel Sambuc {
33433d6423SLionel Sambuc /* This is the main routine of this service. The main loop consists of
34433d6423SLionel Sambuc * three major activities: getting new work, processing the work, and
35433d6423SLionel Sambuc * sending the reply. The loop never terminates, unless a panic occurs.
36433d6423SLionel Sambuc */
37433d6423SLionel Sambuc int result;
38433d6423SLionel Sambuc
39433d6423SLionel Sambuc /* SEF local startup. */
40433d6423SLionel Sambuc env_setargs(argc, argv);
41433d6423SLionel Sambuc sef_local_startup();
42433d6423SLionel Sambuc
43433d6423SLionel Sambuc /* Main loop - get work and do it, forever. */
44433d6423SLionel Sambuc while (TRUE) {
45433d6423SLionel Sambuc /* Wait for incoming message, sets 'callnr' and 'who'. */
46433d6423SLionel Sambuc get_work();
47433d6423SLionel Sambuc
48433d6423SLionel Sambuc if (is_notify(callnr)) {
49433d6423SLionel Sambuc switch (_ENDPOINT_P(who_e)) {
50433d6423SLionel Sambuc case TTY_PROC_NR:
51433d6423SLionel Sambuc result = do_fkey_pressed(&m_in);
52433d6423SLionel Sambuc break;
53433d6423SLionel Sambuc default:
54433d6423SLionel Sambuc /* FIXME: error message. */
55433d6423SLionel Sambuc result = EDONTREPLY;
56433d6423SLionel Sambuc break;
57433d6423SLionel Sambuc }
58433d6423SLionel Sambuc }
59433d6423SLionel Sambuc else {
60433d6423SLionel Sambuc printf("IS: warning, got illegal request %d from %d\n",
61433d6423SLionel Sambuc callnr, m_in.m_source);
62433d6423SLionel Sambuc result = EDONTREPLY;
63433d6423SLionel Sambuc }
64433d6423SLionel Sambuc
65433d6423SLionel Sambuc /* Finally send reply message, unless disabled. */
66433d6423SLionel Sambuc if (result != EDONTREPLY) {
67433d6423SLionel Sambuc reply(who_e, result);
68433d6423SLionel Sambuc }
69433d6423SLionel Sambuc }
70433d6423SLionel Sambuc return(OK); /* shouldn't come here */
71433d6423SLionel Sambuc }
72433d6423SLionel Sambuc
73433d6423SLionel Sambuc /*===========================================================================*
74433d6423SLionel Sambuc * sef_local_startup *
75433d6423SLionel Sambuc *===========================================================================*/
76*4aa48abaSRichard Sailer static void
sef_local_startup(void)77*4aa48abaSRichard Sailer sef_local_startup(void)
78433d6423SLionel Sambuc {
79433d6423SLionel Sambuc /* Register init callbacks. */
80433d6423SLionel Sambuc sef_setcb_init_fresh(sef_cb_init_fresh);
81433d6423SLionel Sambuc sef_setcb_init_lu(sef_cb_init_fresh);
82433d6423SLionel Sambuc sef_setcb_init_restart(sef_cb_init_fresh);
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc /* Register signal callbacks. */
85433d6423SLionel Sambuc sef_setcb_signal_handler(sef_cb_signal_handler);
86433d6423SLionel Sambuc
87433d6423SLionel Sambuc /* Let SEF perform startup. */
88433d6423SLionel Sambuc sef_startup();
89433d6423SLionel Sambuc }
90433d6423SLionel Sambuc
91433d6423SLionel Sambuc /*===========================================================================*
92433d6423SLionel Sambuc * sef_cb_init_fresh *
93433d6423SLionel Sambuc *===========================================================================*/
sef_cb_init_fresh(int UNUSED (type),sef_init_info_t * UNUSED (info))94433d6423SLionel Sambuc static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info))
95433d6423SLionel Sambuc {
96433d6423SLionel Sambuc /* Initialize the information server. */
97433d6423SLionel Sambuc
98433d6423SLionel Sambuc /* Set key mappings. */
99433d6423SLionel Sambuc map_unmap_fkeys(TRUE /*map*/);
100433d6423SLionel Sambuc
101433d6423SLionel Sambuc return(OK);
102433d6423SLionel Sambuc }
103433d6423SLionel Sambuc
104433d6423SLionel Sambuc /*===========================================================================*
105433d6423SLionel Sambuc * sef_cb_signal_handler *
106433d6423SLionel Sambuc *===========================================================================*/
sef_cb_signal_handler(int signo)107433d6423SLionel Sambuc static void sef_cb_signal_handler(int signo)
108433d6423SLionel Sambuc {
109433d6423SLionel Sambuc /* Only check for termination signal, ignore anything else. */
110433d6423SLionel Sambuc if (signo != SIGTERM) return;
111433d6423SLionel Sambuc
112433d6423SLionel Sambuc /* Shutting down. Unset key mappings, and quit. */
113433d6423SLionel Sambuc map_unmap_fkeys(FALSE /*map*/);
114433d6423SLionel Sambuc
115433d6423SLionel Sambuc exit(0);
116433d6423SLionel Sambuc }
117433d6423SLionel Sambuc
118433d6423SLionel Sambuc /*===========================================================================*
119433d6423SLionel Sambuc * get_work *
120433d6423SLionel Sambuc *===========================================================================*/
121*4aa48abaSRichard Sailer static void
get_work(void)122*4aa48abaSRichard Sailer get_work(void)
123433d6423SLionel Sambuc {
124433d6423SLionel Sambuc int status = 0;
125433d6423SLionel Sambuc status = sef_receive(ANY, &m_in); /* this blocks until message arrives */
126433d6423SLionel Sambuc if (OK != status)
127433d6423SLionel Sambuc panic("sef_receive failed!: %d", status);
128433d6423SLionel Sambuc who_e = m_in.m_source; /* message arrived! set sender */
129433d6423SLionel Sambuc callnr = m_in.m_type; /* set function call number */
130433d6423SLionel Sambuc }
131433d6423SLionel Sambuc
132433d6423SLionel Sambuc /*===========================================================================*
133433d6423SLionel Sambuc * reply *
134433d6423SLionel Sambuc *===========================================================================*/
135*4aa48abaSRichard Sailer static void
reply(int who,int result)136*4aa48abaSRichard Sailer reply(
137*4aa48abaSRichard Sailer int who, /* destination */
138*4aa48abaSRichard Sailer int result /* report result to replyee */
139*4aa48abaSRichard Sailer )
140433d6423SLionel Sambuc {
141433d6423SLionel Sambuc int send_status;
142433d6423SLionel Sambuc m_out.m_type = result; /* build reply message */
143433d6423SLionel Sambuc send_status = ipc_send(who, &m_out); /* send the message */
144433d6423SLionel Sambuc if (OK != send_status)
145433d6423SLionel Sambuc panic("unable to send reply!: %d", send_status);
146433d6423SLionel Sambuc }
147433d6423SLionel Sambuc
148433d6423SLionel Sambuc
149