summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-01-26 21:57:46 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2017-01-31 15:28:39 +0100
commitbff9c3e9d3270a524eee693f4d44cd83f13e9963 (patch)
tree26f6e76ab0228fdda33e5a438d7b50e27fa91bae /lib/command.c
parent0d9e204694fbdff2ad6c8441ba3008907ddec3db (diff)
lib/tests: add cmd_hostname_set()
To make it possible for testcli to get a clean memory management bill. (Note: XFREE() is NULL-safe, just like free().) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/command.c b/lib/command.c
index 9485beddd9..510699f91b 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1541,6 +1541,14 @@ DEFUN (show_startup_config,
return CMD_SUCCESS;
}
+int
+cmd_hostname_set (const char *hostname)
+{
+ XFREE (MTYPE_HOST, host.name);
+ host.name = hostname ? XSTRDUP (MTYPE_HOST, hostname) : NULL;
+ return CMD_SUCCESS;
+}
+
/* Hostname configuration */
DEFUN (config_hostname,
hostname_cmd,
@@ -1556,11 +1564,7 @@ DEFUN (config_hostname,
return CMD_WARNING;
}
- if (host.name)
- XFREE (MTYPE_HOST, host.name);
-
- host.name = XSTRDUP (MTYPE_HOST, word->arg);
- return CMD_SUCCESS;
+ return cmd_hostname_set (word->arg);
}
DEFUN (config_no_hostname,
@@ -1570,10 +1574,7 @@ DEFUN (config_no_hostname,
"Reset system's network name\n"
"Host name of this router\n")
{
- if (host.name)
- XFREE (MTYPE_HOST, host.name);
- host.name = NULL;
- return CMD_SUCCESS;
+ return cmd_hostname_set (NULL);
}
/* VTY interface password set. */