Change in osmo-bts[master]: main: do not use fprintf to log fatal errors

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/.

dexter gerrit-no-reply at lists.osmocom.org
Thu Jun 17 10:42:00 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/24707 )


Change subject: main: do not use fprintf to log fatal errors
......................................................................

main: do not use fprintf to log fatal errors

In main there are some fatal errors that lead into exiting osmo-bts. The
errors are logged via fprintf. Those messages are not unimportant for
finding faults, so lets use LOGP() to benefit from the libosmocore
logging system.

Change-Id: I2ae4acf6a92137236e1b62c2d0aab79a34134f45
---
M src/common/main.c
1 file changed, 15 insertions(+), 15 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/07/24707/1

diff --git a/src/common/main.c b/src/common/main.c
index 0b7d3fb..79e97c8 100644
--- a/src/common/main.c
+++ b/src/common/main.c
@@ -92,19 +92,19 @@
 	case 1:
 		vty_ref_mode = get_string_value(vty_ref_gen_mode_names, optarg);
 		if (vty_ref_mode < 0) {
-			fprintf(stderr, "%s: Unknown VTY reference generation "
+			LOGP(DLGLOBAL, LOGL_FATAL, "%s: Unknown VTY reference generation "
 				"mode '%s'\n", prog_name, optarg);
 			exit(2);
 		}
 		break;
 	case 2:
-		fprintf(stderr, "Generating the VTY reference in mode '%s' (%s)\n",
+		LOGP(DLGLOBAL, LOGL_FATAL, "Generating the VTY reference in mode '%s' (%s)\n",
 			get_value_string(vty_ref_gen_mode_names, vty_ref_mode),
 			get_value_string(vty_ref_gen_mode_desc, vty_ref_mode));
 		vty_dump_xml_ref_mode(stdout, (enum vty_ref_gen_mode) vty_ref_mode);
 		exit(0);
 	default:
-		fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
+		LOGP(DLGLOBAL, LOGL_FATAL, "%s: error parsing cmdline options\n", prog_name);
 		exit(2);
 	}
 }
@@ -303,7 +303,7 @@
 
 	g_bts = gsm_bts_alloc(tall_bts_ctx, 0);
 	if (!g_bts) {
-		fprintf(stderr, "Failed to create BTS structure\n");
+		LOGP(DLGLOBAL, LOGL_FATAL, "Failed to create BTS structure\n");
 		exit(1);
 	}
 
@@ -315,14 +315,14 @@
 		param.sched_priority = rt_prio;
 		rc = sched_setscheduler(getpid(), SCHED_RR, &param);
 		if (rc != 0) {
-			fprintf(stderr, "Setting SCHED_RR priority(%d) failed: %s\n",
+			LOGP(DLGLOBAL, LOGL_FATAL, "Setting SCHED_RR priority(%d) failed: %s\n",
 				param.sched_priority, strerror(errno));
 			exit(1);
 		}
 	}
 
 	if (bts_init(g_bts) < 0) {
-		fprintf(stderr, "unable to open bts\n");
+		LOGP(DLGLOBAL, LOGL_FATAL, "unable to open bts\n");
 		exit(1);
 	}
 
@@ -330,19 +330,19 @@
 
 	rc = vty_read_config_file(config_file, NULL);
 	if (rc < 0) {
-		fprintf(stderr, "Failed to parse the config file: '%s'\n",
+		LOGP(DLGLOBAL, LOGL_FATAL, "Failed to parse the config file: '%s'\n",
 			config_file);
 		exit(1);
 	}
 
 	if (!phy_link_by_num(0)) {
-		fprintf(stderr, "You need to configure at least phy0\n");
+		LOGP(DLGLOBAL, LOGL_FATAL, "You need to configure at least phy0\n");
 		exit(1);
 	}
 
 	llist_for_each_entry(trx, &g_bts->trx_list, list) {
 		if (!trx->pinst) {
-			fprintf(stderr, "TRX %u has no associated PHY instance\n",
+			LOGP(DLGLOBAL, LOGL_FATAL, "TRX %u has no associated PHY instance\n",
 				trx->nr);
 			exit(1);
 		}
@@ -370,7 +370,7 @@
 		g_bts->gsmtap.inst = gsmtap_source_init(g_bts->gsmtap.remote_host,
 							GSMTAP_UDP_PORT, 1);
 		if (g_bts->gsmtap.inst == NULL) {
-			fprintf(stderr, "Failed during gsmtap_source_init()\n");
+			LOGP(DLGLOBAL, LOGL_FATAL, "Failed during gsmtap_source_init()\n");
 			exit(1);
 		}
 		gsmtap_source_add_sink(g_bts->gsmtap.inst);
@@ -381,12 +381,12 @@
 	rc = telnet_init_dynif(tall_bts_ctx, NULL, vty_get_bind_addr(),
 			       g_vty_port_num);
 	if (rc < 0) {
-		fprintf(stderr, "Error initializing telnet\n");
+		LOGP(DLGLOBAL, LOGL_FATAL, "Error initializing telnet\n");
 		exit(1);
 	}
 
 	if (pcu_sock_init(g_bts->pcu.sock_path)) {
-		fprintf(stderr, "PCU L1 socket failed\n");
+		LOGP(DLGLOBAL, LOGL_FATAL, "PCU L1 socket failed\n");
 		exit(1);
 	}
 
@@ -398,19 +398,19 @@
 	osmo_init_ignore_signals();
 
 	if (!g_bts->bsc_oml_host) {
-		fprintf(stderr, "Cannot start BTS without knowing BSC OML IP\n");
+		LOGP(DABIS, LOGL_FATAL, "Cannot start BTS without knowing BSC OML IP\n");
 		exit(1);
 	}
 
 	line = abis_open(g_bts, g_bts->bsc_oml_host, "osmo-bts");
 	if (!line) {
-		fprintf(stderr, "unable to connect to BSC\n");
+		LOGP(DABIS, LOGL_FATAL, "unable to connect to BSC\n");
 		exit(2);
 	}
 
 	rc = phy_links_open();
 	if (rc < 0) {
-		fprintf(stderr, "unable to open PHY link(s)\n");
+		LOGP(DLGLOBAL, LOGL_FATAL, "unable to open PHY link(s)\n");
 		exit(2);
 	}
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/24707
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I2ae4acf6a92137236e1b62c2d0aab79a34134f45
Gerrit-Change-Number: 24707
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210617/e620d6b4/attachment.htm>


More information about the gerrit-log mailing list