]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib/tests: add cmd_hostname_set()
authorDavid Lamparter <equinox@opensourcerouting.org>
Thu, 26 Jan 2017 20:57:46 +0000 (21:57 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 31 Jan 2017 14:28:39 +0000 (15:28 +0100)
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>
lib/command.c
lib/command.h
tests/common-cli.c

index 9485beddd9bdc587f9829425d94dd8b4f6a15e74..510699f91b2eda6fc3a3b7cd75734aa5221e83b0 100644 (file)
@@ -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. */
index 3c3c3ae3701eb91f129271a4a2b7d011367aaf7c..89867037087b7f22366a42a0d09f373d28cb6966 100644 (file)
@@ -424,6 +424,8 @@ extern void cmd_terminate (void);
 extern void cmd_exit (struct vty *vty);
 extern int cmd_list_cmds (struct vty *vty, int do_permute);
 
+extern int cmd_hostname_set (const char *hostname);
+
 /* NOT safe for general use; call this only if DEV_BUILD! */
 extern void grammar_sandbox_init (void);
 
index dc1f052bc2587c613132597b0a01bb40957e56cf..7f7d253e6cc9e9eddad88a26f7e7e1859d4fce4f 100644 (file)
@@ -72,7 +72,7 @@ main (int argc, char **argv)
 
   /* Library inits. */
   cmd_init (1);
-  host.name = XSTRDUP(MTYPE_HOST,"test");
+  cmd_hostname_set ("test");
 
   vty_init (master);
   memory_init ();