]> git.puffer.fish Git - mirror/frr.git/commitdiff
vtysh: infer integrated config usage from existence of Quagga.conf
authorChristian Franke <nobody@nowhere.ws>
Mon, 26 Sep 2016 20:01:37 +0000 (22:01 +0200)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 12 Oct 2016 11:42:25 +0000 (07:42 -0400)
Only write to integrated config if integrated config is configured
explicitly or it is already in use.

Signed-off-by: Christian Franke <chris@opensourcerouting.org>
vtysh/vtysh.c
vtysh/vtysh.h
vtysh/vtysh_config.c

index 4f64283a0e27758836317ae09d0a693274e23d25..9663a58528ce8cc8b41d3d19dfbb7980ac87a6b6 100644 (file)
@@ -75,8 +75,7 @@ struct vtysh_client vtysh_client[] =
   { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH, .next = NULL},
 };
 
-/* Using integrated config from Quagga.conf. Default is no. */
-int vtysh_writeconfig_integrated = 1;
+enum vtysh_write_integrated vtysh_write_integrated = WRITE_INTEGRATED_UNSPECIFIED;
 
 extern char config_default[];
 
@@ -2482,7 +2481,7 @@ DEFUN (vtysh_integrated_config,
        "Set up miscellaneous service\n"
        "Write configuration into integrated file\n")
 {
-  vtysh_writeconfig_integrated = 1;
+  vtysh_write_integrated = WRITE_INTEGRATED_YES;
   return CMD_SUCCESS;
 }
 
@@ -2493,7 +2492,7 @@ DEFUN (no_vtysh_integrated_config,
        "Set up miscellaneous service\n"
        "Write configuration into integrated file\n")
 {
-  vtysh_writeconfig_integrated = 0;
+  vtysh_write_integrated = WRITE_INTEGRATED_NO;
   return CMD_SUCCESS;
 }
 
@@ -2573,6 +2572,23 @@ write_config_integrated(void)
   return CMD_SUCCESS;
 }
 
+static bool vtysh_writeconfig_integrated(void)
+{
+  struct stat s;
+
+  switch (vtysh_write_integrated)
+    {
+    case WRITE_INTEGRATED_UNSPECIFIED:
+      if (stat(integrate_default, &s) && errno == ENOENT)
+        return false;
+      return true;
+    case WRITE_INTEGRATED_NO:
+      return false;
+    case WRITE_INTEGRATED_YES:
+      return true;
+    }
+}
+
 DEFUN (vtysh_write_memory,
        vtysh_write_memory_cmd,
        "write memory",
@@ -2585,7 +2601,7 @@ DEFUN (vtysh_write_memory,
   FILE *fp;
 
   /* If integrated Quagga.conf explicitely set. */
-  if (vtysh_writeconfig_integrated)
+  if (vtysh_writeconfig_integrated())
     return write_config_integrated();
   else
     backup_config_file(integrate_default);
index e82aba6b6f6cfb3b9639d271ea5681e92a10be3d..3aa7b8dc835f85bcedef502cfd83fc54aa57c1ad 100644 (file)
@@ -45,6 +45,14 @@ DECLARE_MGROUP(MVTYSH)
 #define VTYSH_DEFAULT_CONFIG "vtysh.conf"
 #define QUAGGA_DEFAULT_CONFIG "Quagga.conf"
 
+enum vtysh_write_integrated {
+       WRITE_INTEGRATED_UNSPECIFIED,
+       WRITE_INTEGRATED_NO,
+       WRITE_INTEGRATED_YES
+};
+
+extern enum vtysh_write_integrated vtysh_write_integrated;
+
 void vtysh_init_vty (void);
 void vtysh_init_cmd (void);
 extern int vtysh_connect_all (const char *optional_daemon_name);
index eb58497310b639b29634ccb003350eca371f6a20..4b0a39084338842467ba9611c196973421c03b10 100644 (file)
@@ -33,8 +33,6 @@ DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CONFIG_LINE, "Vtysh configuration line")
 
 vector configvec;
 
-extern int vtysh_writeconfig_integrated;
-
 struct config
 {
   /* Configuration node name. */
@@ -458,8 +456,10 @@ vtysh_config_write ()
       sprintf (line, "hostname %s", host.name);
       vtysh_config_parse_line(line);
     }
-  if (!vtysh_writeconfig_integrated)
+  if (vtysh_write_integrated == WRITE_INTEGRATED_NO)
     vtysh_config_parse_line ("no service integrated-vtysh-config");
+  if (vtysh_write_integrated == WRITE_INTEGRATED_YES)
+    vtysh_config_parse_line ("service integrated-vtysh-config");
 
   user_config_write ();
 }