Fixed extern declaration from pointer to array
[minix.git] / servers / ipc / main.c
blobd5f4c02a53853d4afb9c4221072b94f46395bafd
1 #include "inc.h"
3 PUBLIC int identifier = 0x1234;
4 PUBLIC endpoint_t who_e;
5 PUBLIC int call_type;
6 PUBLIC endpoint_t SELF_E;
8 struct {
9 int type;
10 int (*func)(message *);
11 int reply; /* whether the reply action is passed through */
12 } ipc_calls[] = {
13 { IPC_SHMGET, do_shmget, 0 },
14 { IPC_SHMAT, do_shmat, 0 },
15 { IPC_SHMDT, do_shmdt, 0 },
16 { IPC_SHMCTL, do_shmctl, 0 },
17 { IPC_SEMGET, do_semget, 0 },
18 { IPC_SEMCTL, do_semctl, 0 },
19 { IPC_SEMOP, do_semop, 1 },
22 #define SIZE(a) (sizeof(a)/sizeof(a[0]))
24 int verbose = 0;
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 PUBLIC int main(int argc, char *argv[])
32 message m;
34 /* SEF local startup. */
35 env_setargs(argc, argv);
36 sef_local_startup();
38 while (TRUE) {
39 int r;
40 int i;
42 if ((r = sef_receive(ANY, &m)) != OK)
43 printf("sef_receive failed %d.\n", r);
44 who_e = m.m_source;
45 call_type = m.m_type;
47 if(verbose)
48 printf("IPC: get %d from %d\n", call_type, who_e);
50 if (call_type & NOTIFY_MESSAGE) {
51 switch (who_e) {
52 case PM_PROC_NR:
53 /* PM sends a notify() on shutdown,
54 * checkout if there are still IPC keys,
55 * give warning messages.
57 if (!is_sem_nil() || !is_shm_nil())
58 printf("IPC: exit with un-clean states.\n");
59 break;
60 case VM_PROC_NR:
61 /* currently, only semaphore needs such information. */
62 sem_process_vm_notify();
63 break;
64 default:
65 printf("IPC: ignoring notify() from %d\n",
66 who_e);
67 break;
69 continue;
72 /* dispatch messages */
73 for (i = 0; i < SIZE(ipc_calls); i++) {
74 if (ipc_calls[i].type == call_type) {
75 int result;
77 result = ipc_calls[i].func(&m);
79 if (ipc_calls[i].reply)
80 break;
82 m.m_type = result;
84 if(verbose && result != OK)
85 printf("IPC: error for %d: %d\n",
86 call_type, result);
88 if ((r = sendnb(who_e, &m)) != OK)
89 printf("IPC send error %d.\n", r);
90 break;
94 if (i == SIZE(ipc_calls)) {
95 /* warn and then ignore */
96 printf("IPC unknown call type: %d from %d.\n",
97 call_type, who_e);
99 update_refcount_and_destroy();
102 /* no way to get here */
103 return -1;
106 /*===========================================================================*
107 * sef_local_startup *
108 *===========================================================================*/
109 PRIVATE void sef_local_startup()
111 /* Register init callbacks. */
112 sef_setcb_init_fresh(sef_cb_init_fresh);
113 sef_setcb_init_restart(sef_cb_init_fresh);
115 /* No live update support for now. */
117 /* Let SEF perform startup. */
118 sef_startup();
121 /*===========================================================================*
122 * sef_cb_init_fresh *
123 *===========================================================================*/
124 PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
126 /* Initialize the ipc server. */
128 SELF_E = getprocnr();
130 if(verbose)
131 printf("IPC: self: %d\n", SELF_E);
133 return(OK);