diff --git a/src/vty/command.c b/src/vty/command.c index 1719690b7..d37516afe 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -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; }