3 int identifier
= 0x1234;
10 int (*func
)(message
*);
11 int reply
; /* whether the reply action is passed through */
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 static int verbose
= 0;
26 /* SEF functions and variables. */
27 static void sef_local_startup(void);
28 static int sef_cb_init_fresh(int type
, sef_init_info_t
*info
);
29 static void sef_cb_signal_handler(int signo
);
31 int main(int argc
, char *argv
[])
35 /* SEF local startup. */
36 env_setargs(argc
, argv
);
43 if ((r
= sef_receive(ANY
, &m
)) != OK
)
44 printf("sef_receive failed %d.\n", r
);
49 printf("IPC: get %d from %d\n", call_type
, who_e
);
51 if (call_type
& NOTIFY_MESSAGE
) {
54 /* currently, only semaphore needs such information. */
55 sem_process_vm_notify();
58 printf("IPC: ignoring notify() from %d\n",
66 * The ipc number in the table can be obtained
67 * with a simple equation because the values of
68 * IPC system calls are consecutive and begin
72 ipc_number
= call_type
- (IPC_BASE
+ 1);
74 /* dispatch message */
75 if (ipc_number
>= 0 && ipc_number
< SIZE(ipc_calls
)) {
78 if (ipc_calls
[ipc_number
].type
!= call_type
)
79 panic("IPC: call table order mismatch");
81 /* If any process does an IPC call,
82 * we have to know about it exiting.
83 * Tell VM to watch it for us.
85 if(vm_watch_exit(m
.m_source
) != OK
) {
86 printf("IPC: watch failed on %d\n", m
.m_source
);
89 result
= ipc_calls
[ipc_number
].func(&m
);
92 * The handler of the IPC call did not
95 if (!ipc_calls
[ipc_number
].reply
) {
99 if(verbose
&& result
!= OK
)
100 printf("IPC: error for %d: %d\n",
103 if ((r
= sendnb(who_e
, &m
)) != OK
)
104 printf("IPC send error %d.\n", r
);
107 /* warn and then ignore */
108 printf("IPC unknown call type: %d from %d.\n",
111 update_refcount_and_destroy();
114 /* no way to get here */
118 /*===========================================================================*
119 * sef_local_startup *
120 *===========================================================================*/
121 static void sef_local_startup()
123 /* Register init callbacks. */
124 sef_setcb_init_fresh(sef_cb_init_fresh
);
125 sef_setcb_init_restart(sef_cb_init_fresh
);
127 /* No live update support for now. */
129 /* Register signal callbacks. */
130 sef_setcb_signal_handler(sef_cb_signal_handler
);
132 /* Let SEF perform startup. */
136 /*===========================================================================*
137 * sef_cb_init_fresh *
138 *===========================================================================*/
139 static int sef_cb_init_fresh(int UNUSED(type
), sef_init_info_t
*UNUSED(info
))
141 /* Initialize the ipc server. */
143 SELF_E
= getprocnr();
146 printf("IPC: self: %d\n", SELF_E
);
151 /*===========================================================================*
152 * sef_cb_signal_handler *
153 *===========================================================================*/
154 static void sef_cb_signal_handler(int signo
)
156 /* Only check for termination signal, ignore anything else. */
157 if (signo
!= SIGTERM
) return;
159 /* Checkout if there are still IPC keys. Inform the user in that case. */
160 if (!is_sem_nil() || !is_shm_nil())
161 printf("IPC: exit with un-clean states.\n");