From 903e2515f5d92b152804ae4afbe67499d0a90d61 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 7 Sep 2017 12:23:16 +0200 Subject: [PATCH] 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 --- src/host/layer23/src/mobile/app_mobile.c | 3 ++- src/host/layer23/src/mobile/main.c | 24 ++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c index 7dc7208cb..fd2c94fb2 100644 --- a/src/host/layer23/src/mobile/app_mobile.c +++ b/src/host/layer23/src/mobile/app_mobile.c @@ -409,12 +409,13 @@ int l23_app_init(int (*mncc_recv)(struct osmocom_ms *ms, int, void *), " using: 'touch %s'\n", config_file); return rc; } + printf("Using configuration from %s\n", config_file); } vty_reading = 0; rc = telnet_init_dynif(l23_ctx, NULL, vty_ip, vty_port); if (rc < 0) return rc; - printf("VTY available on port %u.\n", vty_port); + printf("VTY available on %s %u\n", vty_ip, vty_port); osmo_signal_register_handler(SS_GLOBAL, &global_signal_cb, NULL); osmo_signal_register_handler(SS_L1CTL, &mobile_signal_cb, NULL); diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c index 630bc5356..4a2e4ec65 100644 --- a/src/host/layer23/src/mobile/main.c +++ b/src/host/layer23/src/mobile/main.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -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);