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