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
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)
}
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)
{
}
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;
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);
{
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);
}
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 =
{