diff options
author | Christian Franke <nobody@nowhere.ws> | 2016-09-26 22:01:37 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-10-12 13:42:25 +0200 |
commit | 039eaca36717fb9bfe415cc47b4d36848c54b51f (patch) | |
tree | 161fac0b6f69c4d325311cafd33b7b9082e0dede /vtysh | |
parent | bgp: Fix bi->extra->tag if statement (diff) | |
download | frr-039eaca36717fb9bfe415cc47b4d36848c54b51f.tar.xz frr-039eaca36717fb9bfe415cc47b4d36848c54b51f.zip |
vtysh: infer integrated config usage from existence of Quagga.conf
Only write to integrated config if integrated config is configured
explicitly or it is already in use.
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
Diffstat (limited to 'vtysh')
-rw-r--r-- | vtysh/vtysh.c | 26 | ||||
-rw-r--r-- | vtysh/vtysh.h | 8 | ||||
-rw-r--r-- | vtysh/vtysh_config.c | 6 |
3 files changed, 32 insertions, 8 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 4f64283a0..9663a5852 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -75,8 +75,7 @@ struct vtysh_client vtysh_client[] = { .fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .path = PIM_VTYSH_PATH, .next = NULL}, }; -/* Using integrated config from Quagga.conf. Default is no. */ -int vtysh_writeconfig_integrated = 1; +enum vtysh_write_integrated vtysh_write_integrated = WRITE_INTEGRATED_UNSPECIFIED; extern char config_default[]; @@ -2482,7 +2481,7 @@ DEFUN (vtysh_integrated_config, "Set up miscellaneous service\n" "Write configuration into integrated file\n") { - vtysh_writeconfig_integrated = 1; + vtysh_write_integrated = WRITE_INTEGRATED_YES; return CMD_SUCCESS; } @@ -2493,7 +2492,7 @@ DEFUN (no_vtysh_integrated_config, "Set up miscellaneous service\n" "Write configuration into integrated file\n") { - vtysh_writeconfig_integrated = 0; + vtysh_write_integrated = WRITE_INTEGRATED_NO; return CMD_SUCCESS; } @@ -2573,6 +2572,23 @@ write_config_integrated(void) return CMD_SUCCESS; } +static bool vtysh_writeconfig_integrated(void) +{ + struct stat s; + + switch (vtysh_write_integrated) + { + case WRITE_INTEGRATED_UNSPECIFIED: + if (stat(integrate_default, &s) && errno == ENOENT) + return false; + return true; + case WRITE_INTEGRATED_NO: + return false; + case WRITE_INTEGRATED_YES: + return true; + } +} + DEFUN (vtysh_write_memory, vtysh_write_memory_cmd, "write memory", @@ -2585,7 +2601,7 @@ DEFUN (vtysh_write_memory, FILE *fp; /* If integrated Quagga.conf explicitely set. */ - if (vtysh_writeconfig_integrated) + if (vtysh_writeconfig_integrated()) return write_config_integrated(); else backup_config_file(integrate_default); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index e82aba6b6..3aa7b8dc8 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -45,6 +45,14 @@ DECLARE_MGROUP(MVTYSH) #define VTYSH_DEFAULT_CONFIG "vtysh.conf" #define QUAGGA_DEFAULT_CONFIG "Quagga.conf" +enum vtysh_write_integrated { + WRITE_INTEGRATED_UNSPECIFIED, + WRITE_INTEGRATED_NO, + WRITE_INTEGRATED_YES +}; + +extern enum vtysh_write_integrated vtysh_write_integrated; + void vtysh_init_vty (void); void vtysh_init_cmd (void); extern int vtysh_connect_all (const char *optional_daemon_name); diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index eb5849731..4b0a39084 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -33,8 +33,6 @@ DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CONFIG_LINE, "Vtysh configuration line") vector configvec; -extern int vtysh_writeconfig_integrated; - struct config { /* Configuration node name. */ @@ -458,8 +456,10 @@ vtysh_config_write () sprintf (line, "hostname %s", host.name); vtysh_config_parse_line(line); } - if (!vtysh_writeconfig_integrated) + if (vtysh_write_integrated == WRITE_INTEGRATED_NO) vtysh_config_parse_line ("no service integrated-vtysh-config"); + if (vtysh_write_integrated == WRITE_INTEGRATED_YES) + vtysh_config_parse_line ("service integrated-vtysh-config"); user_config_write (); } |