diff --git a/inc/context.h b/inc/context.h index 05d08c8..24ce233 100644 --- a/inc/context.h +++ b/inc/context.h @@ -1,4 +1,5 @@ #include +#include #include #include /* for offsetof() macro */ #include @@ -6,5 +7,6 @@ typedef struct { uint64_t query_counter; + bool stdout_dbg; TS_RESP_CTX *resp_ctx; } rfc3161_context; diff --git a/inc/http.h b/inc/http.h index 533f23e..24aa7f0 100644 --- a/inc/http.h +++ b/inc/http.h @@ -1,4 +1,5 @@ +#include #include "utils.h" #include "rfc3161.h" -int http_server_start(); +int http_server_start(char *conffile, bool stdout_dbg); diff --git a/src/cmd/uts-server.c b/src/cmd/uts-server.c index fc8291f..f50c363 100644 --- a/src/cmd/uts-server.c +++ b/src/cmd/uts-server.c @@ -19,14 +19,16 @@ static char doc[] = "\nUTS micro timestamp server (RFC 3161)"; static struct argp_option options[] = { {"conffile", 'c', "CONFFILE", 0, "Path to configuration file"}, {"daemonize", 'd', 0, 0, "Launch as a daemon"}, + {"debug", 'D', 0, 0, "STDOUT debugging"}, {0}}; /* A description of the arguments we accept. */ -static char args_doc[] = "-c CONFFILE -d"; +static char args_doc[] = "-c CONFFILE [-d] [-D]"; struct arguments { char *args[2]; /* arg1 & arg2 */ int daemonize; + bool stdout_dbg; char *conffile; }; @@ -39,6 +41,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { case 'd': arguments->daemonize = 1; break; + case 'D': + arguments->stdout_dbg = 1; + break; case 'c': arguments->conffile = arg; break; @@ -62,13 +67,12 @@ int main(int argc, char **argv) { while (1) { // TODO: Insert daemon code here. - http_server_start(); - syslog(LOG_NOTICE, "First daemon started."); - sleep(5); + http_server_start(args.conffile, args.stdout_dbg); + syslog(LOG_NOTICE, "uts-server daemon started."); break; } - syslog(LOG_NOTICE, "First daemon terminated."); + syslog(LOG_NOTICE, "uts-server daemon terminated."); closelog(); return EXIT_SUCCESS; diff --git a/src/lib/http.c b/src/lib/http.c index 37da1c4..167ce6b 100644 --- a/src/lib/http.c +++ b/src/lib/http.c @@ -100,7 +100,7 @@ int rfc3161_handler(struct mg_connection *conn, void *context) { return 1; } -int http_server_start() { +int http_server_start(char *conffile, bool stdout_dbg) { struct mg_context *ctx; struct mg_callbacks callbacks; @@ -115,6 +115,7 @@ int http_server_start() { // Start the web server. ctx = mg_start(&callbacks, NULL, options); rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context)); + ct->stdout_dbg = stdout_dbg; mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct); // Wait until user hits "enter". Server is running in separate thread.