summaryrefslogtreecommitdiffstats
path: root/vtysh/vtysh.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2015-05-20 03:29:18 +0200
committerDonald Sharp <sharpd@cumulusnetworks.com>2015-05-20 03:29:18 +0200
commita72222764f81b2fff68e8648bf88fd2da9835017 (patch)
tree76a5d2e3069cc77a7cecdbe0c43f7028b5dfce4d /vtysh/vtysh.c
parentvtysh: service integrated-vtysh-config not being written to file (diff)
downloadfrr-a72222764f81b2fff68e8648bf88fd2da9835017.tar.xz
frr-a72222764f81b2fff68e8648bf88fd2da9835017.zip
quagga: vtysh-integrated-fix.patch
Fixup to allow 'no service-integrated-vtysh' to work properly and vice versa Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com> Reviewed-by:
Diffstat (limited to 'vtysh/vtysh.c')
-rw-r--r--vtysh/vtysh.c78
1 files changed, 64 insertions, 14 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c
index 2967dedcb..b1c9f453b 100644
--- a/vtysh/vtysh.c
+++ b/vtysh/vtysh.c
@@ -2001,26 +2001,34 @@ DEFUN (no_vtysh_integrated_config,
return CMD_SUCCESS;
}
-static int
-write_config_integrated(void)
+static void
+backup_config_file (const char *fbackup)
{
- u_int i;
- char line[] = "write terminal\n";
- FILE *fp;
char *integrate_sav = NULL;
- integrate_sav = malloc (strlen (integrate_default) +
+ integrate_sav = malloc (strlen (fbackup) +
strlen (CONF_BACKUP_EXT) + 1);
- strcpy (integrate_sav, integrate_default);
+ strcpy (integrate_sav, fbackup);
strcat (integrate_sav, CONF_BACKUP_EXT);
- fprintf (stdout,"Building Configuration...\n");
-
/* Move current configuration file to backup config file. */
unlink (integrate_sav);
- rename (integrate_default, integrate_sav);
+ rename (fbackup, integrate_sav);
free (integrate_sav);
-
+}
+
+static int
+write_config_integrated(void)
+{
+ u_int i;
+ char line[] = "write terminal\n";
+ FILE *fp, *fp1;
+
+ fprintf (stdout,"Building Configuration...\n");
+
+ backup_config_file(integrate_default);
+ backup_config_file(host.config);
+
fp = fopen (integrate_default, "w");
if (fp == NULL)
{
@@ -2029,6 +2037,18 @@ write_config_integrated(void)
return CMD_SUCCESS;
}
+ fp1 = fopen (host.config, "w");
+ if (fp1 == NULL)
+ {
+ fprintf (stdout,"%% Can't open configuration file %s.\n",
+ host.config);
+ return CMD_SUCCESS;
+ }
+
+ vtysh_config_write ();
+ vtysh_config_dump (fp1);
+
+ fclose (fp1);
for (i = 0; i < array_size(vtysh_client); i++)
vtysh_client_config (&vtysh_client[i], line);
@@ -2040,10 +2060,16 @@ write_config_integrated(void)
if (chmod (integrate_default, CONFIGFILE_MASK) != 0)
{
fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
- integrate_default, safe_strerror(errno), errno);
+ integrate_default, safe_strerror(errno), errno);
return CMD_WARNING;
}
+ if (chmod (host.config, CONFIGFILE_MASK) != 0)
+ {
+ fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
+ integrate_default, safe_strerror(errno), errno);
+ return CMD_WARNING;
+ }
fprintf(stdout,"Integrated configuration saved to %s\n",integrate_default);
fprintf (stdout,"[OK]\n");
@@ -2060,16 +2086,40 @@ DEFUN (vtysh_write_memory,
int ret = CMD_SUCCESS;
char line[] = "write memory\n";
u_int i;
-
+ FILE *fp;
+
/* If integrated Quagga.conf explicitely set. */
if (vtysh_writeconfig_integrated)
return write_config_integrated();
+ else
+ backup_config_file(integrate_default);
fprintf (stdout,"Building Configuration...\n");
for (i = 0; i < array_size(vtysh_client); i++)
ret = vtysh_client_execute (&vtysh_client[i], line, stdout);
-
+
+
+ fp = fopen(host.config, "w");
+ if (fp == NULL)
+ {
+ fprintf (stdout,"%% Can't open configuration file %s.\n",
+ host.config);
+ return CMD_SUCCESS;
+ }
+
+ vtysh_config_write ();
+ vtysh_config_dump (fp);
+
+ fclose (fp);
+
+ if (chmod (host.config, CONFIGFILE_MASK) != 0)
+ {
+ fprintf (stdout,"%% Can't chmod configuration file %s: %s (%d)\n",
+ integrate_default, safe_strerror(errno), errno);
+ return CMD_WARNING;
+ }
+
fprintf (stdout,"[OK]\n");
return ret;