diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2016-11-08 19:01:06 +0100 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2016-11-09 13:43:33 +0100 |
| commit | a68f861653da95eeddf96f2afabd481db2798613 (patch) | |
| tree | c05e34df7468a0a18893ba07912d94181d543dd4 | |
| parent | cb947ba3aeb154ea2ad7a55ac09ac624d05978ae (diff) | |
vtysh: add -w option for integrated-config write
This new option is intended to be used both by watchquagga as well as
directly by users. It performs the collect-configuration operation and
writes out Quagga.conf, regardless of whether integrated-config is
enabled or not.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
| -rw-r--r-- | vtysh/vtysh.c | 10 | ||||
| -rw-r--r-- | vtysh/vtysh.h | 1 | ||||
| -rw-r--r-- | vtysh/vtysh_main.c | 25 |
3 files changed, 30 insertions, 6 deletions
diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index cb98a11e90..671eba58eb 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2458,8 +2458,8 @@ backup_config_file (const char *fbackup) free (integrate_sav); } -static int -write_config_integrated(void) +int +vtysh_write_config_integrated(void) { u_int i; char line[] = "write terminal\n"; @@ -2498,7 +2498,7 @@ write_config_integrated(void) return CMD_SUCCESS; } -static bool vtysh_writeconfig_integrated(void) +static bool want_config_integrated(void) { struct stat s; @@ -2529,8 +2529,8 @@ DEFUN (vtysh_write_memory, fprintf (stdout, "Note: this version of vtysh never writes vtysh.conf\n"); /* If integrated Quagga.conf explicitely set. */ - if (vtysh_writeconfig_integrated()) - return write_config_integrated(); + if (want_config_integrated()) + return vtysh_write_config_integrated(); fprintf (stdout,"Building Configuration...\n"); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 08b24731bc..d515918e03 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -75,6 +75,7 @@ void config_add_line (struct list *, const char *); int vtysh_mark_file(const char *filename); int vtysh_read_config (const char *); +int vtysh_write_config_integrated (void); void vtysh_config_parse_line (const char *); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index a82acda17d..f2e62ba815 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -167,6 +167,7 @@ usage (int status) "-E, --echo Echo prompt and command in -c mode\n" \ "-C, --dryrun Check configuration for validity and exit\n" \ "-m, --markfile Mark input file with context end\n" + "-w, --writeconfig Write integrated config (Quagga.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" \ @@ -190,6 +191,7 @@ struct option longopts[] = { "help", no_argument, NULL, 'h'}, { "noerror", no_argument, NULL, 'n'}, { "mark", no_argument, NULL, 'm'}, + { "writeconfig", no_argument, NULL, 'w'}, { 0 } }; @@ -290,6 +292,7 @@ main (int argc, char **argv, char **env) int echo_command = 0; int no_error = 0; int markfile = 0; + int writeconfig = 0; int ret = 0; char *homedir = NULL; @@ -303,7 +306,7 @@ main (int argc, char **argv, char **env) /* Option handling. */ while (1) { - opt = getopt_long (argc, argv, "be:c:d:nf:mEhC", longopts, 0); + opt = getopt_long (argc, argv, "be:c:d:nf:mEhCw", longopts, 0); if (opt == EOF) break; @@ -347,6 +350,9 @@ main (int argc, char **argv, char **env) case 'C': dryrun = 1; break; + case 'w': + writeconfig = 1; + break; case 'h': usage (0); break; @@ -356,6 +362,18 @@ main (int argc, char **argv, char **env) } } + if (markfile + writeconfig + dryrun + boot_flag > 1) + { + fprintf (stderr, "Invalid combination of arguments. Please specify at " + "most one of:\n\t-b, -C, -m, -w\n"); + return 1; + } + if (inputfile && (writeconfig || boot_flag)) + { + fprintf (stderr, "WARNING: Combinining the -f option with -b or -w is " + "NOT SUPPORTED since its\nresults are inconsistent!\n"); + } + /* Initialize user input buffer. */ line_read = NULL; setlinebuf(stdout); @@ -423,6 +441,11 @@ main (int argc, char **argv, char **env) exit(1); } + if (writeconfig) + { + return vtysh_write_config_integrated (); + } + if (inputfile) { vtysh_flock_config (inputfile); |
