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_snapshot(&m
);
75 case COMMON_GETSYSINFO
:
76 result
= do_getsysinfo(&m
);
79 printf("DS: warning, got illegal request from %d\n", m
.m_source
);
84 /* Finally send reply message, unless disabled. */
85 if (result
!= EDONTREPLY
) {
86 m
.m_type
= result
; /* build reply message */
87 reply(who_e
, &m
); /* send it away */
90 return(OK
); /* shouldn't come here */
93 /*===========================================================================*
95 *===========================================================================*/
96 static void sef_local_startup()
98 /* Register init callbacks. */
99 sef_setcb_init_fresh(sef_cb_init_fresh
);
100 sef_setcb_init_restart(sef_cb_init_fail
);
102 /* No live update support for now. */
104 /* Let SEF perform startup. */
108 /*===========================================================================*
110 *===========================================================================*/
111 static void get_work(
112 message
*m_ptr
/* message buffer */
115 int status
= sef_receive(ANY
, m_ptr
); /* blocks until message arrives */
117 panic("failed to receive message!: %d", status
);
118 who_e
= m_ptr
->m_source
; /* message arrived! set sender */
119 callnr
= m_ptr
->m_type
; /* set function call number */
122 /*===========================================================================*
124 *===========================================================================*/
126 endpoint_t who_e
, /* destination */
127 message
*m_ptr
/* message buffer */
130 int s
= send(who_e
, m_ptr
); /* send the message */
132 printf("DS: unable to send reply to %d: %d\n", who_e
, s
);