2 * This service implements a little publish/subscribe data store that is
3 * crucial for the system's fault tolerance. Components that require state
4 * can store it here, for later retrieval, e.g., after a crash and subsequent
5 * restart by the reincarnation server.
8 * Oct 19, 2005 by Jorrit N. Herder
11 #include "inc.h" /* include master header file */
12 #include <minix/endpoint.h>
14 /* Allocate space for the global variables. */
15 static endpoint_t who_e
; /* caller's proc number */
16 static int callnr
; /* system call number */
18 /* Declare some local functions. */
19 static void get_work(message
*m_ptr
);
20 static void reply(endpoint_t whom
, message
*m_ptr
);
22 /* SEF functions and variables. */
23 static void sef_local_startup(void);
25 /*===========================================================================*
27 *===========================================================================*/
28 int main(int argc
, char **argv
)
30 /* This is the main routine of this service. The main loop consists of
31 * three major activities: getting new work, processing the work, and
32 * sending the reply. The loop never terminates, unless a panic occurs.
37 /* SEF local startup. */
38 env_setargs(argc
, argv
);
41 /* Main loop - get work and do it, forever. */
44 /* Wait for incoming message, sets 'callnr' and 'who'. */
47 if (is_notify(callnr
)) {
48 printf("DS: warning, got illegal notify from: %d\n", m
.m_source
);
55 result
= do_publish(&m
);
58 result
= do_retrieve(&m
);
60 case DS_RETRIEVE_LABEL
:
61 result
= do_retrieve_label(&m
);
64 result
= do_delete(&m
);
67 result
= do_subscribe(&m
);
70 result
= do_check(&m
);
73 result
= do_getsysinfo(&m
);
76 printf("DS: warning, got illegal request from %d\n", m
.m_source
);
81 /* Finally send reply message, unless disabled. */
82 if (result
!= EDONTREPLY
) {
83 m
.m_type
= result
; /* build reply message */
84 reply(who_e
, &m
); /* send it away */
87 return(OK
); /* shouldn't come here */
90 /*===========================================================================*
92 *===========================================================================*/
93 static void sef_local_startup()
95 /* Register init callbacks. */
96 sef_setcb_init_fresh(sef_cb_init_fresh
);
97 sef_setcb_init_restart(sef_cb_init_fail
);
99 /* No live update support for now. */
101 /* Let SEF perform startup. */
105 /*===========================================================================*
107 *===========================================================================*/
108 static void get_work(
109 message
*m_ptr
/* message buffer */
112 int status
= sef_receive(ANY
, m_ptr
); /* blocks until message arrives */
114 panic("failed to receive message!: %d", status
);
115 who_e
= m_ptr
->m_source
; /* message arrived! set sender */
116 callnr
= m_ptr
->m_type
; /* set function call number */
119 /*===========================================================================*
121 *===========================================================================*/
123 endpoint_t who_e
, /* destination */
124 message
*m_ptr
/* message buffer */
127 int s
= ipc_send(who_e
, m_ptr
); /* send the message */
129 printf("DS: unable to send reply to %d: %d\n", who_e
, s
);