With this function, users of the Open vSwitch libraries which
should not have the same version as Open vSwitch can manually set a
version number.

Signed-off-by: Ethan Jackson <et...@nicira.com>
---
 lib/util.c |   22 ++++++++++++++++++----
 lib/util.h |    8 ++++++--
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/lib/util.c b/lib/util.c
index 2402ac6..45de277 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -284,21 +284,35 @@ ovs_retval_to_string(int retval)
  * be called at the beginning of main() with "argv[0]" as the argument
  * to 'argv0'.
  *
+ * If the caller's program is not part of Open vSwitch, but just linking
+ * against its libraries, 'version' should be non-null to indicate the callers
+ * version.  Otherwise the caller is assumed to be part of Open vSwitch and
+ * have the same version as this library.
+ *
  * 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)
+set_program_name__(const char *argv0, const char *version, 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"\n"
-                                "Compiled %s %s\n",
-                                program_name, date, time);
+
+    if (!version) {
+        program_version = xasprintf("%s (Open vSwitch) "VERSION"\n"
+                                    "Compiled %s %s\n",
+                                    program_name, date, time);
+    } else {
+        program_version = xasprintf("%s %s\n"
+                                    "Open vSwitch Library "VERSION"\n"
+                                    "Compiled %s %s\n",
+                                    program_name, version, date, time);
+    }
 }
 
 /* Returns a pointer to a string describing the program version.  The
diff --git a/lib/util.h b/lib/util.h
index 9318fa7..f44c5ce 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -162,9 +162,13 @@ rightmost_1bit(uintmax_t x)
 extern "C" {
 #endif
 
-void set_program_name__(const char *name, const char *date, const char *time);
+void set_program_name__(const char *name, const char *version,
+                        const char *date, const char *time);
+#define set_program_name_version(name, version) \
+        set_program_name__(name, version, __DATE__, __TIME__)
+
 #define set_program_name(name) \
-        set_program_name__(name, __DATE__, __TIME__)
+        set_program_name_version(name, NULL)
 
 const char *get_program_version(void);
 void ovs_print_version(uint8_t min_ofp, uint8_t max_ofp);
-- 
1.7.9.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to