From: Christian Franke Date: Mon, 26 Sep 2016 20:01:37 +0000 (+0200) Subject: vtysh: infer integrated config usage from existence of Quagga.conf X-Git-Tag: frr-2.0-rc1~154 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=039eaca36717fb9bfe415cc47b4d36848c54b51f;p=mirror%2Ffrr.git 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 --- diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 4f64283a0e..9663a58528 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 e82aba6b6f..3aa7b8dc83 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 eb58497310..4b0a390843 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 (); }