X-Git-Url: https://git.sommitrealweird.co.uk/quagga-debian.git/blobdiff_plain/191fe7a34582876de01d3e62c2a6587baf59a283..064d9c633233495319bcaa66335ea3d24c0bd7a1:/lib/command.c diff --git a/lib/command.c b/lib/command.c index 662f8a3..e1d9ff6 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1700,7 +1700,7 @@ cmd_element_match(struct cmd_element *cmd_element, * That vector will contain all struct command_token* of the * cmd_element which matched against the given vline at the given * index. - * @return A code specifying if an error occured. If all went right, it's + * @return A code specifying if an error occurred. If all went right, it's * CMD_SUCCESS. */ static int @@ -2812,7 +2812,7 @@ command_config_read_one_line (struct vty *vty, struct cmd_element **cmd, int use ret != CMD_SUCCESS && ret != CMD_WARNING && ret != CMD_ERR_NOTHING_TODO && vty->node != CONFIG_NODE) { vty->node = node_parent(vty->node); - ret = cmd_execute_command_strict (vline, vty, NULL); + ret = cmd_execute_command_strict (vline, vty, cmd); } // If climbing the tree did not work then ignore the command and @@ -3071,7 +3071,7 @@ DEFUN (config_write_file, "Write to configuration file\n") { unsigned int i; - int fd; + int fd, dupfd = -1; struct cmd_node *node; char *config_file; char *config_file_tmp = NULL; @@ -3124,7 +3124,20 @@ DEFUN (config_write_file, if ((*node->func) (file_vty)) vty_out (file_vty, "!\n"); } + + if ((dupfd = dup (file_vty->wfd)) < 0) + { + vty_out (vty, "Couldn't dup fd (for fdatasync) for %s, %s (%d).%s", + config_file, safe_strerror(errno), errno, VTY_NEWLINE); + } + vty_close (file_vty); + + if (fdatasync (dupfd) < 0) + { + vty_out (vty, "Couldn't fdatasync %s, %s (%d)!%s", + config_file, safe_strerror(errno), errno, VTY_NEWLINE); + } if (unlink (config_file_sav) != 0) if (errno != ENOENT) @@ -3139,21 +3152,12 @@ DEFUN (config_write_file, VTY_NEWLINE); goto finished; } - sync (); - if (unlink (config_file) != 0) + if (rename (config_file_tmp, 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) - { - vty_out (vty, "Can't save configuration file %s.%s", config_file, - VTY_NEWLINE); + vty_out (vty, "Can't move configuration file %s into place.%s", + config_file, VTY_NEWLINE); goto finished; } - sync (); - if (chmod (config_file, CONFIGFILE_MASK) != 0) { vty_out (vty, "Can't chmod configuration file %s: %s (%d).%s", @@ -3166,6 +3170,8 @@ DEFUN (config_write_file, ret = CMD_SUCCESS; finished: + if (dupfd >= 0) + close (dupfd); unlink (config_file_tmp); XFREE (MTYPE_TMP, config_file_tmp); XFREE (MTYPE_TMP, config_file_sav);