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
This commit is contained in:
Max 2017-09-07 12:23:16 +02:00
parent 281d9ac381
commit 903e2515f5
2 changed files with 16 additions and 11 deletions

View File

@ -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);

View File

@ -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);