#############################################################################*/
#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
#include <stdlib.h>
#include <systemd/sd-bus.h>
#include "logging.h"
#include "ports.h"
#include "stats-collector.h"
+#include "string.h"
#include "zone.h"
#include "zones.h"
struct nw_daemon {
int nrefs;
+ char config_path[PATH_MAX];
nw_config* config;
// Event Loop
return 0;
}
+static int nw_daemon_parse_argv(nw_daemon* daemon, int argc, char* argv[]) {
+ enum {
+ ARG_CONFIG,
+ };
+ int r;
+
+ static const struct option options[] = {
+ { "config", required_argument, NULL, ARG_CONFIG },
+ { NULL },
+ };
+ int c;
+
+ for (;;) {
+ c = getopt_long(argc, argv, "", options, NULL);
+ if (c < 0)
+ break;
+
+ switch (c) {
+ case ARG_CONFIG:
+ r = nw_string_set(daemon->config_path, optarg);
+ if (r < 0)
+ return r;
+
+ break;
+
+ // Abort on any unrecognised option
+ default:
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
static int nw_daemon_setup_loop(nw_daemon* daemon) {
int r;
return 0;
}
-int nw_daemon_create(nw_daemon** daemon) {
+int nw_daemon_create(nw_daemon** daemon, int argc, char* argv[]) {
int r;
nw_daemon* d = calloc(1, sizeof(*d));
// Initialize reference counter
d->nrefs = 1;
+ // Parse command line arguments
+ r = nw_daemon_parse_argv(d, argc, argv);
+ if (r)
+ goto ERROR;
+
// Setup the daemon
r = nw_daemon_setup(d);
if (r)
#include "zone.h"
#include "zones.h"
-int nw_daemon_create(nw_daemon** daemon);
+int nw_daemon_create(nw_daemon** daemon, int argc, char* argv[]);
nw_daemon* nw_daemon_ref(nw_daemon* daemon);
nw_daemon* nw_daemon_unref(nw_daemon* daemon);