hnbgw: add config file and -c cmdline option
Change-Id: I6ac9fa17b35260031c55aab664124d466f60c937
diff --git a/src/hnbgw.c b/src/hnbgw.c
index ff5fafe..01f64a7 100644
--- a/src/hnbgw.c
+++ b/src/hnbgw.c
@@ -389,8 +389,10 @@
static struct {
int daemonize;
+ const char *config_file;
} hnbgw_cmdline_config = {
- 0
+ 0,
+ "osmo-hnbgw.cfg"
};
static void print_usage()
@@ -403,6 +405,7 @@
printf(" -h --help This text.\n");
printf(" -d option --debug=DHNBAP:DSUA:DRUA:DRANAP:DMAIN Enable debugging.\n");
printf(" -D --daemonize Fork the process into a background daemon.\n");
+ printf(" -c --config-file filename The config file to use.\n");
printf(" -s --disable-color\n");
printf(" -T --timestamp Prefix every log line with a timestamp.\n");
printf(" -V --version Print the version of OsmoHNBGW.\n");
@@ -417,6 +420,7 @@
{"help", 0, 0, 'h'},
{"debug", 1, 0, 'd'},
{"daemonize", 0, 0, 'D'},
+ {"config-file", 1, 0, 'c'},
{"disable-color", 0, 0, 's'},
{"timestamp", 0, 0, 'T'},
{"version", 0, 0, 'V' },
@@ -424,7 +428,7 @@
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "hd:DsTVe:",
+ c = getopt_long(argc, argv, "hd:Dc:sTVe:",
long_options, &option_index);
if (c == -1)
break;
@@ -443,6 +447,9 @@
case 'D':
hnbgw_cmdline_config.daemonize = 1;
break;
+ case 'c':
+ hnbgw_cmdline_config.config_file = optarg;
+ break;
case 'T':
log_set_print_timestamp(osmo_stderr_target, 1);
break;
@@ -488,8 +495,13 @@
/* Handle options after vty_init(), for --version */
handle_options(argc, argv);
- /* NOTE: if we add a config file, read the config before
- * fetching the telnet address with vty_get_bind_addr() */
+ rc = vty_read_config_file(hnbgw_cmdline_config.config_file, NULL);
+ if (rc < 0) {
+ LOGP(DMAIN, LOGL_FATAL, "Failed to parse the config file: '%s'\n",
+ hnbgw_cmdline_config.config_file);
+ return 1;
+ }
+
LOGP(DMAIN, LOGL_NOTICE, "VTY at %s %d\n",
vty_get_bind_addr(), 2323);
rc = telnet_init_dynif(NULL, g_hnb_gw, vty_get_bind_addr(), 2323);