From 0dca233ec09c61b25ccb0cf3181c8f2e85e687e6 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 7 Feb 2017 13:44:09 -0500 Subject: [PATCH 1/2] *: Found some instances of Quagga.conf Cleanup Quagga.conf -> Frr.conf Signed-off-by: Donald Sharp --- lib/vty.h | 2 +- tools/frr-reload.py | 4 ++-- vtysh/vtysh.c | 2 +- vtysh/vtysh_main.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/vty.h b/lib/vty.h index f5c019dd61..80b6d3eb2a 100644 --- a/lib/vty.h +++ b/lib/vty.h @@ -198,7 +198,7 @@ struct vty_arg }; /* Integrated configuration file. */ -#define INTEGRATE_DEFAULT_CONFIG "Quagga.conf" +#define INTEGRATE_DEFAULT_CONFIG "Frr.conf" /* Small macro to determine newline is newline only or linefeed needed. */ #define VTY_NEWLINE ((vty->type == VTY_TERM) ? "\r\n" : "\n") diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 1cad55ac34..2dbc60d1f4 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -859,7 +859,7 @@ if __name__ == '__main__': parser.add_argument('--debug', action='store_true', help='Enable debugs', default=False) parser.add_argument('--stdout', action='store_true', help='Log to STDOUT', default=False) parser.add_argument('filename', help='Location of new frr config file') - parser.add_argument('--overwrite', action='store_true', help='Overwrite Quagga.conf with running config output', default=False) + parser.add_argument('--overwrite', action='store_true', help='Overwrite Frr.conf with running config output', default=False) args = parser.parse_args() # Logging @@ -1068,5 +1068,5 @@ if __name__ == '__main__': os.unlink(filename) # Make these changes persistent - if args.overwrite or args.filename != '/etc/quagga/Quagga.conf': + if args.overwrite or args.filename != '/etc/frr/Frr.conf': subprocess.call(['/usr/bin/vtysh', '-c', 'write']) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 6f9273e889..7546b4ddb0 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2636,7 +2636,7 @@ DEFUN (vtysh_write_memory, fprintf (stdout, "Note: this version of vtysh never writes vtysh.conf\n"); - /* If integrated Quagga.conf explicitely set. */ + /* If integrated Frr.conf explicitely set. */ if (want_config_integrated()) { ret = CMD_WARNING; diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 127cb70ad5..49aedae322 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -140,7 +140,7 @@ usage (int status) fprintf (stderr, "Try `%s --help' for more information.\n", progname); else printf ("Usage : %s [OPTION...]\n\n" \ - "Integrated shell for Quagga routing software suite. \n\n" \ + "Integrated shell for FRR. \n\n" \ "-b, --boot Execute boot startup configuration\n" \ "-c, --command Execute argument as command\n" \ "-d, --daemon Connect only to the specified daemon\n" \ @@ -151,7 +151,7 @@ usage (int status) "-m, --markfile Mark input file with context end\n" \ " --vty_socket Override vty socket path\n" \ " --config_dir Override config directory path\n" \ - "-w, --writeconfig Write integrated config (Quagga.conf) and exit\n" \ + "-w, --writeconfig Write integrated config (Frr.conf) and exit\n" \ "-h, --help Display this help and exit\n\n" \ "Note that multiple commands may be executed from the command\n" \ "line by passing multiple -c args, or by embedding linefeed\n" \ @@ -355,7 +355,7 @@ main (int argc, char **argv, char **env) strlcat(vtysh_config_always, vtysh_configfile_name, sizeof(vtysh_config_always)); /* - * Overwrite location for Quagga.conf + * Overwrite location for Frr.conf */ vtysh_configfile_name = strrchr(FRR_DEFAULT_CONFIG, '/'); if (vtysh_configfile_name) From 1520d0aca9acf42faf0433cbe8f66ef9cd97bd0e Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 8 Feb 2017 16:14:10 +0100 Subject: [PATCH 2/2] lib: use fsync() for config writes, plug fd leak sync() has a HUGE impact on systems that perform actual I/O, i.e. real servers... Also, we were leaking a fd on each config write ever since c5e69a0 "lib/vty: add separate output fd support to VTYs" (by myself :( ...) Signed-off-by: David Lamparter --- lib/command.c | 63 ++++++++++++++++++++++++++++++--------------------- lib/vty.c | 9 +++++++- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/lib/command.c b/lib/command.c index 1dcb232c32..6176640bf6 100644 --- a/lib/command.c +++ b/lib/command.c @@ -3139,9 +3139,9 @@ DEFUN (config_write_file, "Write to configuration file\n") { unsigned int i; - int fd; + int fd, dirfd; struct cmd_node *node; - char *config_file; + char *config_file, *slash; char *config_file_tmp = NULL; char *config_file_sav = NULL; int ret = CMD_WARNING; @@ -3161,7 +3161,22 @@ DEFUN (config_write_file, /* Get filename. */ config_file = host.config; - + +#ifndef O_DIRECTORY +#define O_DIRECTORY 0 +#endif + slash = strrchr (config_file, '/'); + if (slash) + { + char *config_dir = XSTRDUP (MTYPE_TMP, config_file); + config_dir[slash - config_file] = '\0'; + dirfd = open(config_dir, O_DIRECTORY | O_RDONLY); + XFREE (MTYPE_TMP, config_dir); + } + else + dirfd = open(".", O_DIRECTORY | O_RDONLY); + /* if dirfd is invalid, directory sync fails, but we're still OK */ + config_file_sav = XMALLOC (MTYPE_TMP, strlen (config_file) + strlen (CONF_BACKUP_EXT) + 1); strcpy (config_file_sav, config_file); @@ -3179,7 +3194,14 @@ DEFUN (config_write_file, VTY_NEWLINE); goto finished; } - + + if (fchmod (fd, CONFIGFILE_MASK) != 0) + { + vty_out (vty, "Can't chmod configuration file %s: %s (%d).%s", + config_file_tmp, safe_strerror(errno), errno, VTY_NEWLINE); + goto finished; + } + /* Make vty for configuration file. */ file_vty = vty_new (); file_vty->wfd = fd; @@ -3208,40 +3230,29 @@ DEFUN (config_write_file, goto finished; } if (link (config_file, config_file_sav) != 0) - { - vty_out (vty, "Can't backup old configuration file %s.%s", config_file_sav, - VTY_NEWLINE); - goto finished; - } - sync (); - if (unlink (config_file) != 0) - { - vty_out (vty, "Can't unlink configuration file %s.%s", config_file, - VTY_NEWLINE); - goto finished; - } + { + vty_out (vty, "Can't backup old configuration file %s.%s", config_file_sav, + VTY_NEWLINE); + goto finished; + } + fsync (dirfd); } - if (link (config_file_tmp, config_file) != 0) + if (rename (config_file_tmp, config_file) != 0) { vty_out (vty, "Can't save configuration file %s.%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", - config_file, safe_strerror(errno), errno, VTY_NEWLINE); - goto finished; - } + fsync (dirfd); vty_out (vty, "Configuration saved to %s%s", config_file, VTY_NEWLINE); ret = CMD_SUCCESS; finished: - unlink (config_file_tmp); + if (ret != CMD_SUCCESS) + unlink (config_file_tmp); + close (dirfd); XFREE (MTYPE_TMP, config_file_tmp); XFREE (MTYPE_TMP, config_file_sav); return ret; diff --git a/lib/vty.c b/lib/vty.c index 9594d68ebd..a39fe9f41b 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -2330,9 +2330,16 @@ vty_close (struct vty *vty) /* Unset vector. */ vector_unset (vtyvec, vty->fd); + if (vty->wfd > 0 && vty->type == VTY_FILE) + fsync (vty->wfd); + /* Close socket. */ if (vty->fd > 0) - close (vty->fd); + { + close (vty->fd); + if (vty->wfd > 0 && vty->wfd != vty->fd) + close (vty->wfd); + } else vty_stdio_reset ();