00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "inc.h"
00012
00013
00014 int who_e;
00015 int callnr;
00016 int sys_panic;
00017
00018 extern int errno;
00019
00020
00021 FORWARD _PROTOTYPE(void init_server, (int argc, char **argv) );
00022 FORWARD _PROTOTYPE(void exit_server, (void) );
00023 FORWARD _PROTOTYPE(void sig_handler, (void) );
00024 FORWARD _PROTOTYPE(void get_work, (message *m_ptr) );
00025 FORWARD _PROTOTYPE(void reply, (int whom, message *m_ptr) );
00026
00027
00028
00029
00030 PUBLIC int main(int argc, char **argv)
00031 {
00032
00033
00034
00035
00036 message m;
00037 int result;
00038 sigset_t sigset;
00039
00040
00041 init_server(argc, argv);
00042
00043
00044 while (TRUE) {
00045
00046
00047 get_work(&m);
00048
00049 switch (callnr) {
00050 case PROC_EVENT:
00051 sig_handler();
00052 continue;
00053 case DS_PUBLISH:
00054 result = do_publish(&m);
00055 break;
00056 case DS_RETRIEVE:
00057 result = do_retrieve(&m);
00058 break;
00059 case DS_SUBSCRIBE:
00060 result = do_subscribe(&m);
00061 break;
00062 case GETSYSINFO:
00063 result = do_getsysinfo(&m);
00064 break;
00065 default:
00066 report("DS","warning, got illegal request from:", m.m_source);
00067 result = EINVAL;
00068 }
00069
00070
00071 if (result != EDONTREPLY) {
00072 m.m_type = result;
00073 reply(who_e, &m);
00074 }
00075 }
00076 return(OK);
00077 }
00078
00079
00080
00081
00082 PRIVATE void init_server(int argc, char **argv)
00083 {
00084
00085 int i, s;
00086 struct sigaction sigact;
00087
00088
00089 sigact.sa_handler = SIG_MESS;
00090 sigact.sa_mask = ~0;
00091 sigact.sa_flags = 0;
00092 if (sigaction(SIGTERM, &sigact, NULL) < 0)
00093 report("DS","warning, sigaction() failed", errno);
00094 }
00095
00096
00097
00098
00099 PRIVATE void sig_handler()
00100 {
00101
00102 sigset_t sigset;
00103 int sig;
00104
00105
00106 if (getsigset(&sigset) != 0) return;
00107
00108
00109 if (sigismember(&sigset, SIGTERM)) {
00110 exit_server();
00111 }
00112 }
00113
00114
00115
00116
00117 PRIVATE void exit_server()
00118 {
00119
00120
00121
00122 exit(0);
00123 }
00124
00125
00126
00127
00128 PRIVATE void get_work(m_ptr)
00129 message *m_ptr;
00130 {
00131 int status = 0;
00132 status = receive(ANY, m_ptr);
00133 if (OK != status)
00134 panic("DS","failed to receive message!", status);
00135 who_e = m_ptr->m_source;
00136 callnr = m_ptr->m_type;
00137 }
00138
00139
00140
00141
00142 PRIVATE void reply(who_e, m_ptr)
00143 int who_e;
00144 message *m_ptr;
00145 {
00146 int s;
00147 s = send(who_e, m_ptr);
00148 if (OK != s)
00149 panic("DS", "unable to send reply!", s);
00150 }
00151