add the passing of the configuration file path and debug flag

This commit is contained in:
kakwa 2016-08-24 23:14:15 +02:00
parent eaf1d51b1c
commit 2619c2a576
4 changed files with 15 additions and 7 deletions

View File

@ -1,4 +1,5 @@
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h> /* for offsetof() macro */
#include <string.h>
@ -6,5 +7,6 @@
typedef struct {
uint64_t query_counter;
bool stdout_dbg;
TS_RESP_CTX *resp_ctx;
} rfc3161_context;

View File

@ -1,4 +1,5 @@
#include <stdbool.h>
#include "utils.h"
#include "rfc3161.h"
int http_server_start();
int http_server_start(char *conffile, bool stdout_dbg);

View File

@ -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;

View File

@ -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.