]> git.proxmox.com Git - mirror_frr.git/commitdiff
vtysh: Ensure an empty string does not get printed for host/domain
authorNico Berlee <nico.berlee@on2it.net>
Sun, 23 Oct 2022 14:42:51 +0000 (16:42 +0200)
committerNico Berlee <nico.berlee@on2it.net>
Tue, 25 Oct 2022 05:40:01 +0000 (07:40 +0200)
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 <nico.berlee@on2it.net>
vtysh/vtysh_config.c

index d98f83dbf6d6f32482a1ca2b0caf2de9d661087b..0f28b49f72474e401ee325f623c1af7086b32bf2 100644 (file)
@@ -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");