[PATCH 2/4] vty: Hide unconfigured BTS on 'write'

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/OpenBSC@lists.osmocom.org/.

Jacob Erlbeck jerlbeck at sysmocom.de
Wed Sep 11 08:46:56 UTC 2013


This prevents the application from crashing when there is a half
configured BTS (e.g. by using the command 'bts 1' when there isn't
a BTS 1) and the 'write' command is used.
---
 openbsc/src/libbsc/bsc_vty.c     |   10 ++++++----
 openbsc/tests/vty_test_runner.py |   11 +++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index 5748945..55564b6 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -598,11 +598,13 @@ static void config_write_bts_single(struct vty *vty, struct gsm_bts *bts)
 	if (bts->excl_from_rf_lock)
 		vty_out(vty, "  rf-lock-exclude%s", VTY_NEWLINE);
 
-	if (bts->model->config_write_bts)
-		bts->model->config_write_bts(vty, bts);
+	if (bts->model) {
+	       if (bts->model->config_write_bts)
+		       bts->model->config_write_bts(vty, bts);
 
-	llist_for_each_entry(trx, &bts->trx_list, list)
-		config_write_trx_single(vty, trx);
+	       llist_for_each_entry(trx, &bts->trx_list, list)
+		       config_write_trx_single(vty, trx);
+	}
 }
 
 static int config_write_bts(struct vty *v)
diff --git a/openbsc/tests/vty_test_runner.py b/openbsc/tests/vty_test_runner.py
index 460b70e..7f71288 100644
--- a/openbsc/tests/vty_test_runner.py
+++ b/openbsc/tests/vty_test_runner.py
@@ -88,6 +88,17 @@ class TestVTYGenericBSC(TestVTYBase):
         self.assertTrue(self.vty.verify("trx 0",['']))
         self.assertEquals(self.vty.node(), 'config-net-bts-trx')
         self.checkForEndAndExit()
+        self.vty.command("write terminal")
+        self.assertTrue(self.vty.verify("exit",['']))
+        self.assertEquals(self.vty.node(), 'config-net-bts')
+        self.assertTrue(self.vty.verify("exit",['']))
+        self.assertTrue(self.vty.verify("bts 1",['']))
+        self.assertEquals(self.vty.node(), 'config-net-bts')
+        self.checkForEndAndExit()
+        self.assertTrue(self.vty.verify("trx 1",['']))
+        self.assertEquals(self.vty.node(), 'config-net-bts-trx')
+        self.checkForEndAndExit()
+        self.vty.command("write terminal")
         self.assertTrue(self.vty.verify("exit",['']))
         self.assertEquals(self.vty.node(), 'config-net-bts')
         self.assertTrue(self.vty.verify("exit",['']))
-- 
1.7.9.5





More information about the OpenBSC mailing list