From: Donald Sharp Date: Wed, 20 May 2015 23:55:57 +0000 (-0700) Subject: vtysh-integrated-fix.patch X-Git-Tag: frr-2.0-rc1~1355 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=e442116524b9471cfe796f15526426924c6d7fea;p=matthieu%2Ffrr.git vtysh-integrated-fix.patch 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 Testing Done: See bugs --- diff --git a/lib/command.c b/lib/command.c index 07f8674e30..b034369d98 100644 --- a/lib/command.c +++ b/lib/command.c @@ -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) { diff --git a/lib/vty.c b/lib/vty.c index c143a681f3..54bbef65a9 100644 --- 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); diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index e7da30ff32..2290091efe 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -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); } diff --git a/vtysh/vtysh_user.c b/vtysh/vtysh_user.c index c074169fdb..27a5fdf98f 100644 --- a/vtysh/vtysh_user.c +++ b/vtysh/vtysh_user.c @@ -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 = {