src/server/daemon/main.c

branch
srvctrl
changeset 158
77f4f0079428
parent 156
724e107983e9
child 254
4784c14aa639
equal deleted inserted replaced
156:724e107983e9 158:77f4f0079428
43 43
44 #include "webserver.h" 44 #include "webserver.h"
45 #include "log.h" 45 #include "log.h"
46 #include "httprequest.h" 46 #include "httprequest.h"
47 #include "httplistener.h" 47 #include "httplistener.h"
48 #include "srvctrl.h"
48 49
49 #include "configmanager.h" 50 #include "configmanager.h"
50 51
51 static int std_pipe_fds[2]; 52 static int std_pipe_fds[2];
52 static WSBool is_daemon; 53 static WSBool is_daemon;
81 /* 82 /*
82 * SIGTERM: stop the server 83 * SIGTERM: stop the server
83 */ 84 */
84 void sig_term(int sig) { 85 void sig_term(int sig) {
85 webserver_shutdown(); 86 webserver_shutdown();
86 exit(EXIT_SUCCESS); 87 //exit(EXIT_SUCCESS);
87 } 88 }
88 89
89 void* log_pipe_thread(void *data) { 90 void* log_pipe_thread(void *data) {
90 //FILE *log_out = fopen("log.txt", "a"); 91 //FILE *log_out = fopen("log.txt", "a");
91 92
97 } 98 }
98 99
99 //fclose(log_out); 100 //fclose(log_out);
100 101
101 return NULL; 102 return NULL;
102 }
103
104 void handle_srvctrl() {
105 int srvctrl = webserver_srvctrl_fd();
106 listen(srvctrl, 8);
107
108 for(;;) {
109 int admin_client = accept(srvctrl, NULL, 0);
110 if(admin_client < 0) {
111 log_ereport(
112 LOG_FAILURE,
113 "srvctrl: accept failed: %s",
114 strerror(errno));
115 continue;
116 }
117
118 // TODO: read commands
119 webserver_shutdown();
120
121 close(admin_client);
122
123 break;
124 }
125 } 103 }
126 104
127 int main(int argc, char **argv) { 105 int main(int argc, char **argv) {
128 //test(); 106 //test();
129 107
197 if(status != 0) { 175 if(status != 0) {
198 log_ereport(LOG_FAILURE, "cannot run server."); 176 log_ereport(LOG_FAILURE, "cannot run server.");
199 return EXIT_FAILURE; 177 return EXIT_FAILURE;
200 } 178 }
201 179
202 handle_srvctrl(); 180 if(srvctrl_wait()) {
181 return EXIT_FAILURE;
182 }
203 183
204 /* TODO: join threads (or not?) */ 184 /* TODO: join threads (or not?) */
205 /* 185 /*
206 while(1) { 186 while(1) {
207 if(is_daemon) { 187 if(is_daemon) {

mercurial