aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Pettit <jpettit@nicira.com>2011-08-02 12:16:44 -0700
committerJustin Pettit <jpettit@nicira.com>2011-08-04 11:15:43 -0700
commit55d5bb44cbca6993494b05a374d4f09ec03c9102 (patch)
tree6be3dce14e11d53528af237252d8bc92d0a1557e
parentf180c2e2ccdfc36801685dc487748b570652da68 (diff)
util: Introduce get_program_version function.
Useful in an upcoming commit.
-rw-r--r--lib/util.c35
-rw-r--r--lib/util.h10
-rw-r--r--ovsdb/ovsdb-client.c2
-rw-r--r--ovsdb/ovsdb-server.c2
-rw-r--r--ovsdb/ovsdb-tool.c2
-rw-r--r--tests/test-openflowd.c2
-rw-r--r--utilities/ovs-appctl.c2
-rw-r--r--utilities/ovs-benchmark.c2
-rw-r--r--utilities/ovs-controller.c2
-rw-r--r--utilities/ovs-dpctl.c2
-rw-r--r--utilities/ovs-ofctl.c2
-rw-r--r--utilities/ovs-vlan-bug-workaround.c2
-rw-r--r--utilities/ovs-vsctl.c2
-rw-r--r--vswitchd/ovs-brcompatd.c2
-rw-r--r--vswitchd/ovs-vswitchd.c2
15 files changed, 46 insertions, 25 deletions
diff --git a/lib/util.c b/lib/util.c
index 639424dd..0b82318c 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -33,6 +33,7 @@ VLOG_DEFINE_THIS_MODULE(util);
COVERAGE_DEFINE(util_xalloc);
const char *program_name;
+static char *program_version;
void
out_of_memory(void)
@@ -277,21 +278,41 @@ ovs_retval_to_string(int retval)
return unknown;
}
-/* Sets program_name based on 'argv0'. Should be called at the beginning of
- * main(), as "set_program_name(argv[0]);". */
-void set_program_name(const char *argv0)
+/* Sets global "program_name" and "program_version" variables. Should
+ * be called at the beginning of main() with "argv[0]" as the argument
+ * to 'argv0'.
+ *
+ * The 'date' and 'time' arguments should likely be called with
+ * "__DATE__" and "__TIME__" to use the time the binary was built.
+ * Alternatively, the "set_program_name" macro may be called to do this
+ * automatically.
+ */
+void
+set_program_name__(const char *argv0, const char *date, const char *time)
{
const char *slash = strrchr(argv0, '/');
program_name = slash ? slash + 1 : argv0;
+
+ free(program_version);
+ program_version = xasprintf("%s (Open vSwitch) "VERSION BUILDNR"\n"
+ "Compiled %s %s\n",
+ program_name, date, time);
+}
+
+/* Returns a pointer to a string describing the program version. The
+ * caller must not modify or free the returned string.
+ */
+const char *
+get_program_version()
+{
+ return program_version;
}
/* Print the version information for the program. */
void
-ovs_print_version(char *date, char *time,
- uint8_t min_ofp, uint8_t max_ofp)
+ovs_print_version(uint8_t min_ofp, uint8_t max_ofp)
{
- printf("%s (Open vSwitch) "VERSION BUILDNR"\n", program_name);
- printf("Compiled %s %s\n", date, time);
+ printf("%s", program_version);
if (min_ofp || max_ofp) {
printf("OpenFlow versions %#x:%#x\n", min_ofp, max_ofp);
}
diff --git a/lib/util.h b/lib/util.h
index 601f49f1..1649c59c 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -140,12 +140,12 @@ extern const char *program_name;
extern "C" {
#endif
-void set_program_name(const char *);
+void set_program_name__(const char *name, const char *date, const char *time);
+#define set_program_name(name) \
+ set_program_name__(name, __DATE__, __TIME__)
-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))
+const char *get_program_version(void);
+void ovs_print_version(uint8_t min_ofp, uint8_t max_ofp);
void out_of_memory(void) NO_RETURN;
void *xmalloc(size_t) MALLOC_LIKE;
diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c
index 2ed11895..d2a9de10 100644
--- a/ovsdb/ovsdb-client.c
+++ b/ovsdb/ovsdb-client.c
@@ -190,7 +190,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case 'v':
diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index 2d332fec..06ac98be 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -709,7 +709,7 @@ parse_options(int argc, char *argv[], char **file_namep,
usage();
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
VLOG_OPTION_HANDLERS
diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
index 74dfa5a5..0e4a5207 100644
--- a/ovsdb/ovsdb-tool.c
+++ b/ovsdb/ovsdb-tool.c
@@ -85,7 +85,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case 'v':
diff --git a/tests/test-openflowd.c b/tests/test-openflowd.c
index b22b2aad..2c913108 100644
--- a/tests/test-openflowd.c
+++ b/tests/test-openflowd.c
@@ -429,7 +429,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
usage();
case 'V':
- OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
+ 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 cd059bf1..699ff7bd 100644
--- a/utilities/ovs-appctl.c
+++ b/utilities/ovs-appctl.c
@@ -147,7 +147,7 @@ parse_command_line(int argc, char *argv[])
break;
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case '?':
diff --git a/utilities/ovs-benchmark.c b/utilities/ovs-benchmark.c
index e4e92257..bc28dab6 100644
--- a/utilities/ovs-benchmark.c
+++ b/utilities/ovs-benchmark.c
@@ -192,7 +192,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case '?':
diff --git a/utilities/ovs-controller.c b/utilities/ovs-controller.c
index 022b1a4d..cb70e4f7 100644
--- a/utilities/ovs-controller.c
+++ b/utilities/ovs-controller.c
@@ -397,7 +397,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
+ ovs_print_version(OFP_VERSION, OFP_VERSION);
exit(EXIT_SUCCESS);
VLOG_OPTION_HANDLERS
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index 415d276e..7962c7a6 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -108,7 +108,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
VLOG_OPTION_HANDLERS
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 6be899b1..39ebe400 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -138,7 +138,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
+ ovs_print_version(OFP_VERSION, OFP_VERSION);
exit(EXIT_SUCCESS);
case OPT_STRICT:
diff --git a/utilities/ovs-vlan-bug-workaround.c b/utilities/ovs-vlan-bug-workaround.c
index 309d64e2..9722c278 100644
--- a/utilities/ovs-vlan-bug-workaround.c
+++ b/utilities/ovs-vlan-bug-workaround.c
@@ -130,7 +130,7 @@ parse_options(int argc, char *argv[])
break;
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case '?':
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index b59d8861..573c9481 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -262,7 +262,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case 't':
diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c
index 3dd25c37..d9b3bc38 100644
--- a/vswitchd/ovs-brcompatd.c
+++ b/vswitchd/ovs-brcompatd.c
@@ -885,7 +885,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(0, 0);
+ ovs_print_version(0, 0);
exit(EXIT_SUCCESS);
case OPT_APPCTL:
diff --git a/vswitchd/ovs-vswitchd.c b/vswitchd/ovs-vswitchd.c
index 7d4e4d77..b2b20821 100644
--- a/vswitchd/ovs-vswitchd.c
+++ b/vswitchd/ovs-vswitchd.c
@@ -151,7 +151,7 @@ parse_options(int argc, char *argv[])
usage();
case 'V':
- OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
+ ovs_print_version(OFP_VERSION, OFP_VERSION);
exit(EXIT_SUCCESS);
case OPT_MLOCKALL: