[MERGED] osmo-sgsn[master]: osmo-gbproxy: use 'osmo-gbproxy.cfg' as default config name

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Thu Mar 15 18:32:08 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: osmo-gbproxy: use 'osmo-gbproxy.cfg' as default config name
......................................................................


osmo-gbproxy: use 'osmo-gbproxy.cfg' as default config name

Like we did in osmo-sgsn in If804da17a7481e79e000fe40ae0d9c4be9722e61, move
from 'osmo_gbproxy.cfg' to 'osmo-gbproxy.cfg' as default config file name.
Still look for the legacy file name to not break old setups.

Change-Id: I9448908d94a23001f04b6334a78739a839b91313
---
M src/gprs/gb_proxy_main.c
1 file changed, 27 insertions(+), 3 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/gprs/gb_proxy_main.c b/src/gprs/gb_proxy_main.c
index 6f62400..1416ff5 100644
--- a/src/gprs/gb_proxy_main.c
+++ b/src/gprs/gb_proxy_main.c
@@ -66,7 +66,10 @@
 	"This is free software: you are free to change and redistribute it.\r\n"
 	"There is NO WARRANTY, to the extent permitted by law.\r\n";
 
-static char *config_file = "osmo_gbproxy.cfg";
+#define CONFIG_FILE_DEFAULT "osmo-gbproxy.cfg"
+#define CONFIG_FILE_LEGACY "osmo_gbproxy.cfg"
+
+static char *config_file = NULL;
 struct gbproxy_config gbcfg = {0};
 static int daemonize = 0;
 
@@ -130,7 +133,7 @@
 	printf("  -h --help this text\n");
 	printf("  -d option --debug=DNS:DGPRS,0:0 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("  -c --config-file filename The config file to use [%s]\n", CONFIG_FILE_DEFAULT);
 	printf("  -s --disable-color\n");
 	printf("  -T --timestamp Prefix every log line with a timestamp\n");
 	printf("  -V --version. Print the version of OpenBSC.\n");
@@ -251,6 +254,12 @@
 	.num_cat = ARRAY_SIZE(gprs_categories),
 };
 
+static bool file_exists(const char *path)
+{
+	struct stat sb;
+	return stat(path, &sb) ? false : true;
+}
+
 int main(int argc, char **argv)
 {
 	int rc;
@@ -277,6 +286,21 @@
 
 	handle_options(argc, argv);
 
+	/* Backwards compatibility: for years, the default config file name was
+	 * osmo_gbproxy.cfg. All other Osmocom programs use osmo-*.cfg with a
+	 * dash. To be able to use the new config file name without breaking
+	 * previous setups that might rely on the legacy default config file
+	 * name, we need to look for the old config file if no -c option was
+	 * passed AND no file exists with the new default file name. */
+	if (!config_file) {
+		/* No -c option was passed */
+		if (file_exists(CONFIG_FILE_LEGACY)
+		    && !file_exists(CONFIG_FILE_DEFAULT))
+			config_file = CONFIG_FILE_LEGACY;
+		else
+			config_file = CONFIG_FILE_DEFAULT;
+	}
+
 	rate_ctr_init(tall_bsc_ctx);
 	osmo_stats_init(tall_bsc_ctx);
 
@@ -294,7 +318,7 @@
 
 	rc = gbproxy_parse_config(config_file, &gbcfg);
 	if (rc < 0) {
-		LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n");
+		LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file '%s'\n", config_file);
 		exit(2);
 	}
 

-- 
To view, visit https://gerrit.osmocom.org/7308
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9448908d94a23001f04b6334a78739a839b91313
Gerrit-PatchSet: 2
Gerrit-Project: osmo-sgsn
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder



More information about the gerrit-log mailing list