1
0
mirror of https://github.com/kakwa/uts-server synced 2024-06-01 16:48:08 +02:00
uts-server/src/cmd/uts-server.c

76 lines
1.8 KiB
C
Raw Normal View History

2015-12-17 15:49:58 +01:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <getopt.h>
#include <argp.h>
#include <sys/syslog.h>
2015-12-18 00:29:43 +01:00
#include "rfc3161.h"
#include "http.h"
2015-12-17 15:49:58 +01:00
const char *argp_program_version = UTS_VERSION;
2016-08-23 19:38:07 +02:00
const char *argp_program_bug_address =
"Pierre-Francois Carpentier <carpentier.pf@gmail.com>";
2015-12-17 15:49:58 +01:00
static char doc[] = "\nUTS micro timestamp server (RFC 3161)";
static struct argp_option options[] = {
2016-08-23 19:38:07 +02:00
{"conffile", 'c', "CONFFILE", 0, "Path to configuration file"},
{"daemonize", 'd', 0, 0, "Launch as a daemon"},
{0}};
2015-12-17 15:49:58 +01:00
/* A description of the arguments we accept. */
static char args_doc[] = "-c CONFFILE -d";
2016-08-23 19:38:07 +02:00
struct arguments {
char *args[2]; /* arg1 & arg2 */
int daemonize;
2015-12-17 15:49:58 +01:00
char *conffile;
};
2016-08-23 19:38:07 +02:00
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
2015-12-17 15:49:58 +01:00
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
struct arguments *arguments = (struct arguments *)state->input;
2016-08-23 19:38:07 +02:00
switch (key) {
case 'd':
arguments->daemonize = 1;
break;
case 'c':
arguments->conffile = arg;
break;
default:
return ARGP_ERR_UNKNOWN;
2015-12-17 15:49:58 +01:00
}
return 0;
}
/* Our argp parser. */
2016-08-23 19:38:07 +02:00
static struct argp argp = {options, parse_opt, args_doc, doc};
2015-12-17 15:49:58 +01:00
2016-08-23 19:38:07 +02:00
int main(int argc, char **argv) {
2015-12-17 15:49:58 +01:00
struct arguments args;
2016-08-23 19:38:07 +02:00
args.conffile = NULL;
2015-12-17 15:49:58 +01:00
args.daemonize = 0;
2016-08-23 19:38:07 +02:00
argp_parse(&argp, argc, argv, 0, 0, &args);
2015-12-17 15:49:58 +01:00
if (args.daemonize)
skeleton_daemon();
2015-12-17 14:09:44 +01:00
2016-08-23 19:38:07 +02:00
while (1) {
// TODO: Insert daemon code here.
2015-12-18 00:29:43 +01:00
http_server_start();
2016-08-23 19:38:07 +02:00
syslog(LOG_NOTICE, "First daemon started.");
sleep(5);
2015-12-17 14:09:44 +01:00
break;
}
2016-08-23 19:38:07 +02:00
syslog(LOG_NOTICE, "First daemon terminated.");
2015-12-17 14:09:44 +01:00
closelog();
return EXIT_SUCCESS;
}