vty: fix 'write file FILE' breaking 'show startup-config'

Change-Id: I224ae41096c12f544dfe35a2c3f381b3bb3ba75e
Related: OS#6440
This commit is contained in:
Vadim Yanitskiy 2024-04-22 09:52:21 +07:00
parent dafdb1181b
commit 5155535be7
1 changed files with 7 additions and 5 deletions

View File

@ -3490,6 +3490,7 @@ DEFUN(config_write_file,
"Write to configuration file\n"
"Set file path to store the config, or replace if already exists\n")
{
const char *config_file;
char *failed_file;
int rc;
@ -3503,15 +3504,16 @@ DEFUN(config_write_file,
}
if (argc == 1)
host_config_set(argv[0]);
if (host.config == NULL) {
config_file = argv[0];
else /* write to the startup config file */
config_file = host_config_file();
if (config_file == NULL) {
vty_out(vty, "Can't save to configuration file, using vtysh.%s",
VTY_NEWLINE);
return CMD_WARNING;
}
rc = write_config_file(host.config, &failed_file);
rc = write_config_file(config_file, &failed_file);
switch (rc) {
case -1:
vty_out(vty, "Can't open configuration file %s.%s",
@ -3544,7 +3546,7 @@ DEFUN(config_write_file,
rc = CMD_WARNING;
break;
default:
vty_out(vty, "Configuration saved to %s%s", host.config, VTY_NEWLINE);
vty_out(vty, "Configuration saved to %s%s", config_file, VTY_NEWLINE);
rc = CMD_SUCCESS;
break;
}