From 36d223bb6b758966ca3de434c723791faf7178ee Mon Sep 17 00:00:00 2001 From: Nico Berlee Date: Sun, 23 Oct 2022 16:42:51 +0200 Subject: [PATCH] vtysh: Ensure an empty string does not get printed for host/domain vtysh show running-config is showing: frr version 8.3.1_git frr defaults traditional hostname test log file /etc/frr/frr.log informational log timestamp precision 3 domainname service integrated-vtysh-config domainname should not be printed in this case at all. If the host has no search/domainname configured, frr_reload.py crashes on invalid config from `vtysh show running-config` Basically the same change as commit a7141b8 Signed-off-by: Nico Berlee --- vtysh/vtysh_config.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index d98f83dbf6..0f28b49f72 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -652,18 +652,21 @@ int vtysh_read_config(const char *config_default_dir, bool dry_run) */ void vtysh_config_write(void) { + const char *name; char line[512]; - if (cmd_hostname_get()) { - snprintf(line, sizeof(line), "hostname %s", cmd_hostname_get()); + name = cmd_hostname_get(); + if (name && name[0] != '\0') { + snprintf(line, sizeof(line), "hostname %s", name); vtysh_config_parse_line(NULL, line); } - if (cmd_domainname_get()) { - snprintf(line, sizeof(line), "domainname %s", - cmd_domainname_get()); + name = cmd_domainname_get(); + if (name && name[0] != '\0') { + snprintf(line, sizeof(line), "domainname %s", name); vtysh_config_parse_line(NULL, line); } + if (vtysh_write_integrated == WRITE_INTEGRATED_NO) vtysh_config_parse_line(NULL, "no service integrated-vtysh-config"); -- 2.39.5