From e57960ee72e83ab5dbd3754289387f9995999c42 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Wed, 20 May 2009 22:18:37 -0700 Subject: [PATCH] Modify version string for various binaries. For applications that understand OpenFlow, print the versions they support. This change also adds that the program is part of the Open vSwitch project. Add support for the "--version" argument to some programs that were missing it. --- extras/ezio/ezio-term.c | 3 +-- extras/ezio/ovs-switchui.c | 3 +-- lib/util.c | 12 ++++++++++++ lib/util.h | 5 +++++ secchan/main.c | 3 +-- utilities/ovs-appctl.c | 11 +++++++++-- utilities/ovs-cfg-mod.c | 12 ++++++++++-- utilities/ovs-controller.c | 2 +- utilities/ovs-discover.c | 3 +-- utilities/ovs-dpctl.c | 3 +-- utilities/ovs-kill.c | 3 +-- utilities/ovs-ofctl.c | 3 +-- vswitchd/brcompatd.c | 3 +-- vswitchd/vswitchd.c | 3 +-- 14 files changed, 46 insertions(+), 23 deletions(-) diff --git a/extras/ezio/ezio-term.c b/extras/ezio/ezio-term.c index 2bda002b..c2177add 100644 --- a/extras/ezio/ezio-term.c +++ b/extras/ezio/ezio-term.c @@ -1020,8 +1020,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s %s compiled "__DATE__" "__TIME__"\n", - program_name, VERSION BUILDNR); + OVS_PRINT_VERSION(0, 0); exit(EXIT_SUCCESS); DAEMON_OPTION_HANDLERS diff --git a/extras/ezio/ovs-switchui.c b/extras/ezio/ovs-switchui.c index 0855abc6..6fbf2523 100644 --- a/extras/ezio/ovs-switchui.c +++ b/extras/ezio/ovs-switchui.c @@ -2993,8 +2993,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s %s compiled "__DATE__" "__TIME__"\n", - program_name, VERSION BUILDNR); + OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION); exit(EXIT_SUCCESS); VLOG_OPTION_HANDLERS diff --git a/lib/util.c b/lib/util.c index 7ad8ba4e..ff392f44 100644 --- a/lib/util.c +++ b/lib/util.c @@ -194,6 +194,18 @@ void set_program_name(const char *argv0) program_name = slash ? slash + 1 : argv0; } +/* Print the version information for the program. */ +void +ovs_print_version(char *date, char *time, + uint8_t min_ofp, uint8_t max_ofp) +{ + printf("%s (Open vSwitch) "VERSION BUILDNR"\n", program_name); + printf("Compiled %s %s\n", date, time); + if (min_ofp || max_ofp) { + printf("OpenFlow versions %#x:%#x\n", min_ofp, max_ofp); + } +} + /* Writes the 'size' bytes in 'buf' to 'stream' as hex bytes arranged 16 per * line. Numeric offsets are also included, starting at 'ofs' for the first * byte in 'buf'. If 'ascii' is true then the corresponding ASCII characters diff --git a/lib/util.h b/lib/util.h index dcb15a4b..710222a2 100644 --- a/lib/util.h +++ b/lib/util.h @@ -97,6 +97,11 @@ extern "C" { void set_program_name(const char *); +void ovs_print_version(char *date, char *time, + uint8_t min_ofp, uint8_t max_ofp); +#define OVS_PRINT_VERSION(min_ofp, max_ofp) \ + ovs_print_version(__DATE__, __TIME__, (min_ofp), (max_ofp)) + void out_of_memory(void) NO_RETURN; void *xmalloc(size_t) MALLOC_LIKE; void *xcalloc(size_t, size_t) MALLOC_LIKE; diff --git a/secchan/main.c b/secchan/main.c index 1b5d5cca..5ed57824 100644 --- a/secchan/main.c +++ b/secchan/main.c @@ -475,8 +475,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s) usage(); case 'V': - printf("%s %s compiled "__DATE__" "__TIME__"\n", - program_name, VERSION BUILDNR); + OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION); exit(EXIT_SUCCESS); DAEMON_OPTION_HANDLERS diff --git a/utilities/ovs-appctl.c b/utilities/ovs-appctl.c index d091dd08..44361b92 100644 --- a/utilities/ovs-appctl.c +++ b/utilities/ovs-appctl.c @@ -62,7 +62,9 @@ usage(char *prog_name, int exit_code) " LEVEL may be 'emer', 'err', 'warn', 'info', or 'dbg' (default)\n" " -r, --reopen Make the program reopen its log file\n" " -e, --execute=COMMAND Execute control COMMAND and print its output\n" - " -h, --help Print this helpful information\n", + "Other options:\n" + " -h, --help Print this helpful information\n" + " -V, --version Display version information\n", prog_name); exit(exit_code); } @@ -138,6 +140,7 @@ int main(int argc, char *argv[]) /* Target options must come first. */ {"target", required_argument, NULL, 't'}, {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'V'}, /* Action options come afterward. */ {"list", no_argument, NULL, 'l'}, @@ -166,7 +169,7 @@ int main(int argc, char *argv[]) if (option == -1) { break; } - if (!strchr("th", option) && n_clients == 0) { + if (!strchr("thV", option) && n_clients == 0) { ovs_fatal(0, "no targets specified (use --help for help)"); } else { ++n_actions; @@ -216,6 +219,10 @@ int main(int argc, char *argv[]) usage(argv[0], EXIT_SUCCESS); break; + case 'V': + OVS_PRINT_VERSION(0, 0); + exit(EXIT_SUCCESS); + case '?': exit(EXIT_FAILURE); diff --git a/utilities/ovs-cfg-mod.c b/utilities/ovs-cfg-mod.c index 03ee3708..fdda7534 100644 --- a/utilities/ovs-cfg-mod.c +++ b/utilities/ovs-cfg-mod.c @@ -57,7 +57,10 @@ usage(char *prog_name, int exit_code) " -D, --del-section=KEY delete section matching KEY\n" " --del-match=PATTERN delete entries matching shell PATTERN\n" " -q, --query=KEY return all entries matching KEY\n" - " -c, --log-changes log changes up to this point\n", + " -c, --log-changes log changes up to this point\n" + "\nOther options:\n" + " -h, --help display this help message\n" + " -V, --version display version information\n", prog_name); exit(exit_code); } @@ -136,6 +139,7 @@ int main(int argc, char *argv[]) {"changes", no_argument, 0, 'c'}, {"verbose", optional_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, {0, 0, 0, 0}, }; char *short_options; @@ -155,7 +159,7 @@ int main(int argc, char *argv[]) break; } - if ((option > UCHAR_MAX || !strchr("Fhv?", option)) + if ((option > UCHAR_MAX || !strchr("FhVv?", option)) && config_set == false) { ovs_fatal(0, "no config file specified (use --help for help)"); } @@ -198,6 +202,10 @@ int main(int argc, char *argv[]) usage(argv[0], EXIT_SUCCESS); break; + case 'V': + OVS_PRINT_VERSION(0, 0); + exit(EXIT_SUCCESS); + case 'v': vlog_set_verbosity(optarg); break; diff --git a/utilities/ovs-controller.c b/utilities/ovs-controller.c index d67bc98b..6c1b4017 100644 --- a/utilities/ovs-controller.c +++ b/utilities/ovs-controller.c @@ -296,7 +296,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s "VERSION" compiled "__DATE__" "__TIME__"\n", argv[0]); + OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION); exit(EXIT_SUCCESS); VLOG_OPTION_HANDLERS diff --git a/utilities/ovs-discover.c b/utilities/ovs-discover.c index 82c8aae1..f899c2f8 100644 --- a/utilities/ovs-discover.c +++ b/utilities/ovs-discover.c @@ -368,8 +368,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s %s compiled "__DATE__" "__TIME__"\n", - program_name, VERSION BUILDNR); + OVS_PRINT_VERSION(0, 0); exit(EXIT_SUCCESS); case 'v': diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index bfd87aff..1406763f 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -148,8 +148,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s %s compiled "__DATE__" "__TIME__"\n", - program_name, VERSION BUILDNR); + OVS_PRINT_VERSION(0, 0); exit(EXIT_SUCCESS); case 'v': diff --git a/utilities/ovs-kill.c b/utilities/ovs-kill.c index 153e431d..935a0bc1 100644 --- a/utilities/ovs-kill.c +++ b/utilities/ovs-kill.c @@ -182,8 +182,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s %s compiled "__DATE__" "__TIME__"\n", - program_name, VERSION BUILDNR); + OVS_PRINT_VERSION(0, 0); exit(EXIT_SUCCESS); case '?': diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index f97e07a8..cd134be6 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -180,8 +180,7 @@ parse_options(int argc, char *argv[], struct settings *s) usage(); case 'V': - printf("%s %s compiled "__DATE__" "__TIME__"\n", - program_name, VERSION BUILDNR); + OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION); exit(EXIT_SUCCESS); case 'v': diff --git a/vswitchd/brcompatd.c b/vswitchd/brcompatd.c index cda9c5cd..8e450727 100644 --- a/vswitchd/brcompatd.c +++ b/vswitchd/brcompatd.c @@ -696,8 +696,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s "VERSION BUILDNR" compiled "__DATE__" "__TIME__"\n", - argv[0]); + OVS_PRINT_VERSION(0, 0); exit(EXIT_SUCCESS); case OPT_LOCK_TIMEOUT: diff --git a/vswitchd/vswitchd.c b/vswitchd/vswitchd.c index abd54356..907e488c 100644 --- a/vswitchd/vswitchd.c +++ b/vswitchd/vswitchd.c @@ -189,8 +189,7 @@ parse_options(int argc, char *argv[]) usage(); case 'V': - printf("%s "VERSION BUILDNR" compiled "__DATE__" "__TIME__"\n", - argv[0]); + OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION); exit(EXIT_SUCCESS); case OPT_FAKE_PROC_NET: -- 2.30.2