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" |
46 |
48 |
95 } |
97 } |
96 |
98 |
97 //fclose(log_out); |
99 //fclose(log_out); |
98 |
100 |
99 return NULL; |
101 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 } |
100 } |
125 } |
101 |
126 |
102 int main(int argc, char **argv) { |
127 int main(int argc, char **argv) { |
103 //test(); |
128 //test(); |
104 |
129 |
162 log_ereport(LOG_INFORM, "startup"); |
187 log_ereport(LOG_INFORM, "startup"); |
163 |
188 |
164 int status; |
189 int status; |
165 status = webserver_init(); |
190 status = webserver_init(); |
166 if(status != 0) { |
191 if(status != 0) { |
167 log_ereport(LOG_FAILURE, "Cannot initialize server."); |
192 log_ereport(LOG_FAILURE, "cannot initialize server."); |
168 return EXIT_FAILURE; |
193 return EXIT_FAILURE; |
169 } |
194 } |
170 |
195 |
171 status = webserver_run(); |
196 status = webserver_run(); |
172 if(status != 0) { |
197 if(status != 0) { |
173 log_ereport(LOG_FAILURE, "Cannot run server."); |
198 log_ereport(LOG_FAILURE, "cannot run server."); |
174 return EXIT_FAILURE; |
199 return EXIT_FAILURE; |
175 } |
200 } |
176 |
201 |
|
202 handle_srvctrl(); |
|
203 |
177 /* TODO: join threads (or not?) */ |
204 /* TODO: join threads (or not?) */ |
|
205 /* |
178 while(1) { |
206 while(1) { |
179 if(is_daemon) { |
207 if(is_daemon) { |
180 fflush(stdout); |
208 fflush(stdout); |
181 fflush(stderr); |
209 fflush(stderr); |
182 } |
210 } |
183 sleep(10000); |
211 sleep(10000); |
184 if(0) { |
212 if(0) { |
185 break; |
213 break; |
186 } |
214 } |
187 } |
215 } |
|
216 */ |
188 |
217 |
189 return EXIT_SUCCESS; |
218 return EXIT_SUCCESS; |
190 } |
219 } |
191 |
220 |