* 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
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
"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;
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)
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",
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);