[PATCH] libosmocore[master]: VTY: allow comments in the same line as vty commands

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

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Sep 14 03:10:35 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/3882

to look at the new patch set (#3).

VTY: allow comments in the same line as vty commands

Note: this breaks users' VTY config when a command's argument starts with a '!'
or '#'.

Allow comments following VTY commands, on the same line. Start a comment with
'!' or '#' following a space, which allows using the comment characters in
command arguments -- just not at the start of an argument.

This patch allows to do:

   remote-ip 10.23.24.1    # where to reach the STP

When they are not preceded by a space, the comment characters still count as
VTY command tokens, i.e. still allowing:

   short-name instance#23

This would parse "instance#23" as name.

(We usually use '!' as the VTY comment delimiter, but the code also allowed and
still allows using '#', hence add both '#' and '!' as same-line comment
delimiter.)

Change-Id: Iccd9cc8604494379910c534b35ce7e74e329d863
---
M src/vty/command.c
M tests/Makefile.am
A tests/vty/ok_comments.cfg
M tests/vty/vty_test.c
M tests/vty/vty_test.ok
5 files changed, 10 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/82/3882/3

diff --git a/src/vty/command.c b/src/vty/command.c
index a65b4de..0f5538a 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -246,6 +246,9 @@
 
 	/* Copy each command piece and set into vector. */
 	while (1) {
+		if (*cp == '!' || *cp == '#')
+			break;
+
 		start = cp;
 		while (!(isspace((int)*cp) || *cp == '\r' || *cp == '\n') &&
 		       *cp != '\0')
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8935bf7..b43d9b7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -222,6 +222,7 @@
 	     vty/fail_tabs_and_spaces.cfg \
 	     vty/fail_too_much_indent.cfg \
 	     vty/ok.cfg \
+	     vty/ok_comments.cfg \
 	     vty/ok_ignore_blank.cfg \
 	     vty/ok_ignore_comment.cfg \
 	     vty/ok_indented_root.cfg \
diff --git a/tests/vty/ok_comments.cfg b/tests/vty/ok_comments.cfg
new file mode 100644
index 0000000..c040892
--- /dev/null
+++ b/tests/vty/ok_comments.cfg
@@ -0,0 +1,3 @@
+line vty ! comments
+ no login # after
+log stderr #commands
diff --git a/tests/vty/vty_test.c b/tests/vty/vty_test.c
index eba9995..27e5b5c 100644
--- a/tests/vty/vty_test.c
+++ b/tests/vty/vty_test.c
@@ -342,6 +342,7 @@
 	test_exit_by_indent("fail_too_much_indent.cfg", -EINVAL);
 	test_exit_by_indent("fail_tabs_and_spaces.cfg", -EINVAL);
 	test_exit_by_indent("ok_indented_root.cfg", 0);
+	test_exit_by_indent("ok_comments.cfg", 0);
 
 	/* Leak check */
 	OSMO_ASSERT(talloc_total_blocks(stats_ctx) == 1);
diff --git a/tests/vty/vty_test.ok b/tests/vty/vty_test.ok
index b2df1a1..a09e7ef 100644
--- a/tests/vty/vty_test.ok
+++ b/tests/vty/vty_test.ok
@@ -128,4 +128,6 @@
 got rc=-22
 reading file ok_indented_root.cfg, expecting rc=0
 got rc=0
+reading file ok_comments.cfg, expecting rc=0
+got rc=0
 All tests passed

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Iccd9cc8604494379910c534b35ce7e74e329d863
Gerrit-PatchSet: 3
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list