--- a/src/server/daemon/main.c Tue Jan 24 17:36:28 2017 +0100 +++ b/src/server/daemon/main.c Tue Jan 24 22:48:14 2017 +0100 @@ -39,6 +39,8 @@ #include "../util/plist.h" #include "../util/date.h" +#include "../../ucx/string.h" + #include "webserver.h" #include "log.h" #include "httprequest.h" @@ -99,6 +101,29 @@ return NULL; } +void handle_srvctrl() { + int srvctrl = webserver_srvctrl_fd(); + listen(srvctrl, 8); + + for(;;) { + int admin_client = accept(srvctrl, NULL, 0); + if(admin_client < 0) { + log_ereport( + LOG_FAILURE, + "srvctrl: accept failed: %s", + strerror(errno)); + continue; + } + + // TODO: read commands + webserver_shutdown(); + + close(admin_client); + + break; + } +} + int main(int argc, char **argv) { //test(); @@ -164,17 +189,20 @@ int status; status = webserver_init(); if(status != 0) { - log_ereport(LOG_FAILURE, "Cannot initialize server."); + log_ereport(LOG_FAILURE, "cannot initialize server."); return EXIT_FAILURE; } status = webserver_run(); if(status != 0) { - log_ereport(LOG_FAILURE, "Cannot run server."); + log_ereport(LOG_FAILURE, "cannot run server."); return EXIT_FAILURE; } - + + handle_srvctrl(); + /* TODO: join threads (or not?) */ +/* while(1) { if(is_daemon) { fflush(stdout); @@ -185,6 +213,7 @@ break; } } +*/ return EXIT_SUCCESS; }