util: Introduce get_program_version function.
authorJustin Pettit <jpettit@nicira.com>
Tue, 2 Aug 2011 19:16:44 +0000 (12:16 -0700)
committerJustin Pettit <jpettit@nicira.com>
Thu, 4 Aug 2011 18:15:43 +0000 (11:15 -0700)
Useful in an upcoming commit.

15 files changed:
lib/util.c
lib/util.h
ovsdb/ovsdb-client.c
ovsdb/ovsdb-server.c
ovsdb/ovsdb-tool.c
tests/test-openflowd.c
utilities/ovs-appctl.c
utilities/ovs-benchmark.c
utilities/ovs-controller.c
utilities/ovs-dpctl.c
utilities/ovs-ofctl.c
utilities/ovs-vlan-bug-workaround.c
utilities/ovs-vsctl.c
vswitchd/ovs-brcompatd.c
vswitchd/ovs-vswitchd.c

index 639424dd6ea683b915c0302e7b5c559066c99d47..0b82318cab8d225b63fbc24d55d1f2910d020248 100644 (file)
@@ -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);
     }
index 601f49f1ba353eece525a204ba9ec355ab2523ca..1649c59c2777937f5e74539832ad403ae5ae6162 100644 (file)
@@ -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;
index 2ed1189523afcea597b250c890b1c4584fd1aa45..d2a9de10e22bf69c4bbfe563bea8d22b82887af0 100644 (file)
@@ -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':
index 2d332fec0703a26a69dfec7535f633fa43be74e3..06ac98be6b2326c4ca3e4bee4bce9cc5d20db4c8 100644 (file)
@@ -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
index 74dfa5a5b99ffa84e5df63edccbe475ebc38fe42..0e4a5207920d18ea60f0c4aed608da085d0032b3 100644 (file)
@@ -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':
index b22b2aad83bf54d5fc833a3a95cc5a17c558fc26..2c913108e3b8aeaff7d66a6afac3103bc01cd785 100644 (file)
@@ -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
index cd059bf1cffa9bbfa995deb734f8805f2d045e4a..699ff7bd14846d801fde82d9f5012d498319714b 100644 (file)
@@ -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 '?':
index e4e9225789d14ad9b40c12948a4235b4de8747c5..bc28dab69b5333b86452495b192f3ca994267469 100644 (file)
@@ -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 '?':
index 022b1a4db98df0895ca7bcfce4b53e5f60402c13..cb70e4f77b5be4eda782b3655b460ac8274f4be8 100644 (file)
@@ -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
index 415d276ec31221b3130f8c3b3337001688ebd18f..7962c7a6f79d153c68999e706952974a643d8c7a 100644 (file)
@@ -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
index 6be899b1e5b4d4531bd90c123829cbe3da54c6a6..39ebe4004344b5d88b6246f1b75dc25aa937a3a5 100644 (file)
@@ -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:
index 309d64e2a687d062b178635f7d8cdb9fa79d4123..9722c27841dedc2e8152825e16975c23dce309ac 100644 (file)
@@ -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 '?':
index b59d8861ce1e019f3452f3980ff4c69a0673deb2..573c9481d29f3f335f9c8bf848700904502d5c1e 100644 (file)
@@ -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':
index 3dd25c37b2e2cf569ea9c13375656a7b58b90812..d9b3bc38d8746804361006e146aa175b38cd4398 100644 (file)
@@ -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:
index 7d4e4d7704797245ea8e9d3deadee1b8f18f1818..b2b208214f9793cf38d64d84371b5cce5897abfb 100644 (file)
@@ -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: