summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/src/mobile/main.c
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-09-07 12:23:16 +0200
committerMax <msuraev@sysmocom.de>2017-09-07 18:08:03 +0200
commit903e2515f5d92b152804ae4afbe67499d0a90d61 (patch)
treeb9e6c576d16ffc17996a159b01f2e1d87e5fe86e /src/host/layer23/src/mobile/main.c
parent281d9ac3818401ec0abe5268528e01c0a6e1a9d8 (diff)
Add arbitrary config file location support
All other Osmocom projects use '-c' command line option to specify the location of config file. Let's do the same with fallback to existing implicit config file name logic. Also print config file path and vty host on startup. Change-Id: Idaac3ff8d1f8541e00c45290db948a67bb899311
Diffstat (limited to 'src/host/layer23/src/mobile/main.c')
-rw-r--r--src/host/layer23/src/mobile/main.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c
index 630bc535..4a2e4ec6 100644
--- a/src/host/layer23/src/mobile/main.c
+++ b/src/host/layer23/src/mobile/main.c
@@ -38,6 +38,7 @@
#include <getopt.h>
#include <stdlib.h>
#include <stdio.h>
+#include <stdbool.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
@@ -51,6 +52,8 @@ struct log_target *stderr_target;
void *l23_ctx = NULL;
struct llist_head ms_list;
static char *gsmtap_ip = 0;
+static const char *config_file = ".osmocom/bb/mobile.cfg";
+bool use_default_cfg = true;
struct gsmtap_inst *gsmtap_inst = NULL;
static char *vty_ip = "127.0.0.1";
unsigned short vty_port = 4247;
@@ -96,6 +99,7 @@ static void print_help()
printf(" -d --debug Change debug flags. default: %s\n",
debug_default);
printf(" -D --daemonize Run as daemon\n");
+ printf(" -c --config-file filename The config file to use.\n");
printf(" -m --mncc-sock Disable built-in MNCC handler and "
"offer socket\n");
}
@@ -111,11 +115,12 @@ static void handle_options(int argc, char **argv)
{"vty-port", 1, 0, 'v'},
{"debug", 1, 0, 'd'},
{"daemonize", 0, 0, 'D'},
+ {"config-file", 1, 0, 'c'},
{"mncc-sock", 0, 0, 'm'},
{0, 0, 0, 0},
};
- c = getopt_long(argc, argv, "hi:u:v:d:Dm",
+ c = getopt_long(argc, argv, "hi:u:c:v:d:Dm",
long_options, &option_index);
if (c == -1)
break;
@@ -132,6 +137,10 @@ static void handle_options(int argc, char **argv)
case 'u':
vty_ip = optarg;
break;
+ case 'c':
+ config_file = optarg;
+ use_default_cfg = false;
+ break;
case 'v':
vty_port = atoi(optarg);
break;
@@ -202,9 +211,6 @@ int main(int argc, char **argv)
int quit = 0;
int rc;
char const * home;
- size_t len;
- const char osmocomcfg[] = ".osmocom/bb/mobile.cfg";
- char *config_file = NULL;
printf("%s\n", openbsc_copyright);
@@ -234,13 +240,11 @@ int main(int argc, char **argv)
gsmtap_source_add_sink(gsmtap_inst);
}
- home = getenv("HOME");
- if (home != NULL) {
- len = strlen(home) + 1 + sizeof(osmocomcfg);
- config_file = talloc_size(l23_ctx, len);
- if (config_file != NULL)
- snprintf(config_file, len, "%s/%s", home, osmocomcfg);
+ if (use_default_cfg) {
+ home = talloc_strdup(l23_ctx, getenv("HOME"));
+ config_file = talloc_asprintf_append(home, "/%s", config_file);
}
+
/* save the config file directory name */
config_dir = talloc_strdup(l23_ctx, config_file);
config_dir = dirname(config_dir);