]> git.puffer.fish Git - matthieu/frr.git/commitdiff
vtysh-integrated-fix.patch
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 23:55:57 +0000 (16:55 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 20 May 2015 23:55:57 +0000 (16:55 -0700)
Lost config when switching back and forth between 'service integrated-vtysh-config'.
Also it was possible to have config files not be read in if they were not generated.

Ticket: CM-6011, CM-6033
Reviewed By: Daniel Walton <dwalton@cumulusnetworks.com>
Testing Done: See bugs

lib/command.c
lib/vty.c
vtysh/vtysh_config.c
vtysh/vtysh_user.c

index 07f8674e309268afd50ffd2ebb0c64b39ebcb953..b034369d98e8e89ec708b1e846490cfe8346abd9 100644 (file)
@@ -3010,6 +3010,7 @@ DEFUN (config_write_file,
   char *config_file_sav = NULL;
   int ret = CMD_WARNING;
   struct vty *file_vty;
+  struct stat conf_stat;
 
   /* Check and see if we are operating under vtysh configuration */
   if (host.config == NULL)
@@ -3058,25 +3059,28 @@ DEFUN (config_write_file,
       }
   vty_close (file_vty);
 
-  if (unlink (config_file_sav) != 0)
-    if (errno != ENOENT)
-      {
-       vty_out (vty, "Can't unlink backup configuration file %s.%s", config_file_sav,
-                VTY_NEWLINE);
-        goto finished;
-      }
-  if (link (config_file, config_file_sav) != 0)
+  if (stat(config_file, &conf_stat) >= 0)
     {
-      vty_out (vty, "Can't backup old configuration file %s.%s", config_file_sav,
-               VTY_NEWLINE);
-      goto finished;
-    }
-  sync ();
-  if (unlink (config_file) != 0)
-    {
-      vty_out (vty, "Can't unlink configuration file %s.%s", config_file,
-               VTY_NEWLINE);
-      goto finished;
+      if (unlink (config_file_sav) != 0)
+       if (errno != ENOENT)
+         {
+           vty_out (vty, "Can't unlink backup configuration file %s.%s", config_file_sav,
+                    VTY_NEWLINE);
+           goto finished;
+         }
+      if (link (config_file, config_file_sav) != 0)
+       {
+         vty_out (vty, "Can't backup old configuration file %s.%s", config_file_sav,
+                  VTY_NEWLINE);
+         goto finished;
+       }
+      sync ();
+      if (unlink (config_file) != 0)
+       {
+         vty_out (vty, "Can't unlink configuration file %s.%s", config_file,
+                  VTY_NEWLINE);
+         goto finished;
+       }
     }
   if (link (config_file_tmp, config_file) != 0)
     {
index c143a681f36fee5965b42ecf892d463bccf63c21..54bbef65a9800fe1c92829907503c01591ffe5e8 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -2366,34 +2366,10 @@ vty_read_config (char *config_file,
     }
   else
     {
-      confp = fopen (config_default_dir, "r");
-      if (confp == NULL)
-        {
-          fprintf (stderr, "%s: failed to open configuration file %s: %s\n",
-                   __func__, config_default_dir, safe_strerror (errno));
-          
-          confp = vty_use_backup_config (config_default_dir);
-          if (confp)
-            {
-              fprintf (stderr, "WARNING: using backup configuration file!\n");
-              fullpath = config_default_dir;
-            }
-          else
-            {
-              fprintf (stderr, "can't open configuration file [%s]\n",
-                                config_default_dir);
-                 exit (1);
-            }
-        }      
-      else
-        fullpath = config_default_dir;
-    }
 
-  host_config_set (fullpath);
+      host_config_set (config_default_dir);
 
 #ifdef VTYSH
-  if (config_file)
-    {
       int ret;
       struct stat conf_stat;
 
@@ -2417,8 +2393,30 @@ vty_read_config (char *config_file,
           if (ret >= 0)
            return;
         }
-    }
 #endif /* VTYSH */
+      confp = fopen (config_default_dir, "r");
+      if (confp == NULL)
+        {
+          fprintf (stderr, "%s: failed to open configuration file %s: %s\n",
+                   __func__, config_default_dir, safe_strerror (errno));
+
+          confp = vty_use_backup_config (config_default_dir);
+          if (confp)
+            {
+              fprintf (stderr, "WARNING: using backup configuration file!\n");
+              fullpath = config_default_dir;
+            }
+          else
+            {
+              fprintf (stderr, "can't open configuration file [%s]\n",
+                      config_default_dir);
+             exit (1);
+            }
+        }
+      else
+        fullpath = config_default_dir;
+    }
+
   vty_read_file (confp);
 
   fclose (confp);
index e7da30ff32c439c888fe41fbb564a66bf20c495f..2290091efe825d761a9b42e87e144307126454df 100644 (file)
@@ -409,13 +409,13 @@ vtysh_read_config (const char *config_default_dir)
 {
   FILE *confp = NULL;
 
+  host_config_set (config_default_dir);
   confp = fopen (config_default_dir, "r");
   if (confp == NULL)
     return (1);
 
   vtysh_read_file (confp);
   fclose (confp);
-  host_config_set (config_default_dir);
 
   return (0);
 }
index c074169fdb5f0b302e98c139019fdb71e961680e..27a5fdf98f2ffe72bfac1862c1cafb1cf9be37ea 100644 (file)
@@ -55,6 +55,9 @@ struct vtysh_user *user_get(const char *);
 int vtysh_auth(void);
 void vtysh_user_init(void);
 
+extern struct list *config_top;
+extern void config_add_line(struct list *config, const char *line);
+
 #ifdef USE_PAM
 static struct pam_conv conv = 
 {