src/server/daemon/main.c

changeset 179
ef6827505bd2
parent 158
77f4f0079428
child 254
4784c14aa639
equal deleted inserted replaced
174:8f2a834d1d68 179:ef6827505bd2
37 #include "../util/pool.h" 37 #include "../util/pool.h"
38 #include "../public/nsapi.h" 38 #include "../public/nsapi.h"
39 #include "../util/plist.h" 39 #include "../util/plist.h"
40 #include "../util/date.h" 40 #include "../util/date.h"
41 41
42 #include "../../ucx/string.h"
43
42 #include "webserver.h" 44 #include "webserver.h"
43 #include "log.h" 45 #include "log.h"
44 #include "httprequest.h" 46 #include "httprequest.h"
45 #include "httplistener.h" 47 #include "httplistener.h"
48 #include "srvctrl.h"
46 49
47 #include "configmanager.h" 50 #include "configmanager.h"
48 51
49 static int std_pipe_fds[2]; 52 static int std_pipe_fds[2];
50 static WSBool is_daemon; 53 static WSBool is_daemon;
79 /* 82 /*
80 * SIGTERM: stop the server 83 * SIGTERM: stop the server
81 */ 84 */
82 void sig_term(int sig) { 85 void sig_term(int sig) {
83 webserver_shutdown(); 86 webserver_shutdown();
84 exit(EXIT_SUCCESS); 87 //exit(EXIT_SUCCESS);
85 } 88 }
86 89
87 void* log_pipe_thread(void *data) { 90 void* log_pipe_thread(void *data) {
88 //FILE *log_out = fopen("log.txt", "a"); 91 //FILE *log_out = fopen("log.txt", "a");
89 92
162 log_ereport(LOG_INFORM, "startup"); 165 log_ereport(LOG_INFORM, "startup");
163 166
164 int status; 167 int status;
165 status = webserver_init(); 168 status = webserver_init();
166 if(status != 0) { 169 if(status != 0) {
167 log_ereport(LOG_FAILURE, "Cannot initialize server."); 170 log_ereport(LOG_FAILURE, "cannot initialize server.");
168 return EXIT_FAILURE; 171 return EXIT_FAILURE;
169 } 172 }
170 173
171 status = webserver_run(); 174 status = webserver_run();
172 if(status != 0) { 175 if(status != 0) {
173 log_ereport(LOG_FAILURE, "Cannot run server."); 176 log_ereport(LOG_FAILURE, "cannot run server.");
174 return EXIT_FAILURE; 177 return EXIT_FAILURE;
175 } 178 }
176 179
180 if(srvctrl_wait()) {
181 return EXIT_FAILURE;
182 }
183
177 /* TODO: join threads (or not?) */ 184 /* TODO: join threads (or not?) */
185 /*
178 while(1) { 186 while(1) {
179 if(is_daemon) { 187 if(is_daemon) {
180 fflush(stdout); 188 fflush(stdout);
181 fflush(stderr); 189 fflush(stderr);
182 } 190 }
183 sleep(10000); 191 sleep(10000);
184 if(0) { 192 if(0) {
185 break; 193 break;
186 } 194 }
187 } 195 }
196 */
188 197
189 return EXIT_SUCCESS; 198 return EXIT_SUCCESS;
190 } 199 }
191 200

mercurial