mirror of
https://github.com/kakwa/uts-server
synced 2025-01-07 12:14:31 +01:00
add the passing of the configuration file path and debug flag
This commit is contained in:
parent
eaf1d51b1c
commit
2619c2a576
@ -1,4 +1,5 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h> /* for offsetof() macro */
|
#include <stddef.h> /* for offsetof() macro */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -6,5 +7,6 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t query_counter;
|
uint64_t query_counter;
|
||||||
|
bool stdout_dbg;
|
||||||
TS_RESP_CTX *resp_ctx;
|
TS_RESP_CTX *resp_ctx;
|
||||||
} rfc3161_context;
|
} rfc3161_context;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "rfc3161.h"
|
#include "rfc3161.h"
|
||||||
|
|
||||||
int http_server_start();
|
int http_server_start(char *conffile, bool stdout_dbg);
|
||||||
|
@ -19,14 +19,16 @@ static char doc[] = "\nUTS micro timestamp server (RFC 3161)";
|
|||||||
static struct argp_option options[] = {
|
static struct argp_option options[] = {
|
||||||
{"conffile", 'c', "CONFFILE", 0, "Path to configuration file"},
|
{"conffile", 'c', "CONFFILE", 0, "Path to configuration file"},
|
||||||
{"daemonize", 'd', 0, 0, "Launch as a daemon"},
|
{"daemonize", 'd', 0, 0, "Launch as a daemon"},
|
||||||
|
{"debug", 'D', 0, 0, "STDOUT debugging"},
|
||||||
{0}};
|
{0}};
|
||||||
|
|
||||||
/* A description of the arguments we accept. */
|
/* A description of the arguments we accept. */
|
||||||
static char args_doc[] = "-c CONFFILE -d";
|
static char args_doc[] = "-c CONFFILE [-d] [-D]";
|
||||||
|
|
||||||
struct arguments {
|
struct arguments {
|
||||||
char *args[2]; /* arg1 & arg2 */
|
char *args[2]; /* arg1 & arg2 */
|
||||||
int daemonize;
|
int daemonize;
|
||||||
|
bool stdout_dbg;
|
||||||
char *conffile;
|
char *conffile;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -39,6 +41,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||||||
case 'd':
|
case 'd':
|
||||||
arguments->daemonize = 1;
|
arguments->daemonize = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'D':
|
||||||
|
arguments->stdout_dbg = 1;
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
arguments->conffile = arg;
|
arguments->conffile = arg;
|
||||||
break;
|
break;
|
||||||
@ -62,13 +67,12 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// TODO: Insert daemon code here.
|
// TODO: Insert daemon code here.
|
||||||
http_server_start();
|
http_server_start(args.conffile, args.stdout_dbg);
|
||||||
syslog(LOG_NOTICE, "First daemon started.");
|
syslog(LOG_NOTICE, "uts-server daemon started.");
|
||||||
sleep(5);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_NOTICE, "First daemon terminated.");
|
syslog(LOG_NOTICE, "uts-server daemon terminated.");
|
||||||
closelog();
|
closelog();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -100,7 +100,7 @@ int rfc3161_handler(struct mg_connection *conn, void *context) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int http_server_start() {
|
int http_server_start(char *conffile, bool stdout_dbg) {
|
||||||
struct mg_context *ctx;
|
struct mg_context *ctx;
|
||||||
struct mg_callbacks callbacks;
|
struct mg_callbacks callbacks;
|
||||||
|
|
||||||
@ -115,6 +115,7 @@ int http_server_start() {
|
|||||||
// Start the web server.
|
// Start the web server.
|
||||||
ctx = mg_start(&callbacks, NULL, options);
|
ctx = mg_start(&callbacks, NULL, options);
|
||||||
rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context));
|
rfc3161_context *ct = (rfc3161_context *)calloc(1, sizeof(rfc3161_context));
|
||||||
|
ct->stdout_dbg = stdout_dbg;
|
||||||
mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct);
|
mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct);
|
||||||
|
|
||||||
// Wait until user hits "enter". Server is running in separate thread.
|
// Wait until user hits "enter". Server is running in separate thread.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user