lib: Add API to set program name and version
authorThomas Graf <tgraf@noironetworks.com>
Mon, 24 Nov 2014 11:49:01 +0000 (12:49 +0100)
committerBen Pfaff <blp@nicira.com>
Tue, 25 Nov 2014 22:32:59 +0000 (14:32 -0800)
Required to have reasonable logging messages.

Signed-off-by: Thomas Graf <tgraf@noironetworks.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
include/openvswitch/automake.mk
include/openvswitch/util.h [new file with mode: 0644]
lib/unixctl.c
lib/util.c
lib/util.h

index 5253e62..cf89f44 100644 (file)
@@ -1,5 +1,6 @@
 openvswitchincludedir = $(includedir)/openvswitch
 openvswitchinclude_HEADERS = \
        include/openvswitch/types.h \
+       include/openvswitch/util.h \
        include/openvswitch/version.h
 
diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
new file mode 100644 (file)
index 0000000..58c2b59
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef OPENVSWITCH_UTIL_H
+#define OPENVSWITCH_UTIL_H 1
+
+#include <openvswitch/version.h>
+
+void ovs_set_program_name__(const char *name, const char *version,
+                            const char *date, const char *time);
+
+#define ovs_set_program_name(name, version) \
+        ovs_set_program_name__(name, version, __DATE__, __TIME__)
+
+const char *ovs_get_program_name(void);
+const char *ovs_get_program_version(void);
+
+#endif
index 76dc933..5749293 100644 (file)
@@ -88,7 +88,7 @@ static void
 unixctl_version(struct unixctl_conn *conn, int argc OVS_UNUSED,
                 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
 {
-    unixctl_command_reply(conn, get_program_version());
+    unixctl_command_reply(conn, ovs_get_program_version());
 }
 
 /* Registers a unixctl command with the given 'name'.  'usage' describes the
index f4d0f8d..453ade6 100644 (file)
@@ -448,12 +448,12 @@ ovs_strerror(int error)
  *
  * 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
+ * Alternatively, the "ovs_set_program_name" macro may be called to do this
  * automatically.
  */
 void
-set_program_name__(const char *argv0, const char *version, const char *date,
-                   const char *time)
+ovs_set_program_name__(const char *argv0, const char *version, const char *date,
+                       const char *time)
 {
     char *basename;
 #ifdef _WIN32
@@ -533,11 +533,20 @@ set_subprogram_name(const char *format, ...)
  * caller must not modify or free the returned string.
  */
 const char *
-get_program_version(void)
+ovs_get_program_version(void)
 {
     return program_version;
 }
 
+/* Returns a pointer to a string describing the program name.  The
+ * caller must not modify or free the returned string.
+ */
+const char *
+ovs_get_program_name(void)
+{
+    return program_name;
+}
+
 /* Print the version information for the program.  */
 void
 ovs_print_version(uint8_t min_ofp, uint8_t max_ofp)
index 2258315..8ef80c0 100644 (file)
@@ -29,6 +29,7 @@
 #include "byte-order.h"
 #include "compiler.h"
 #include "openvswitch/types.h"
+#include "openvswitch/util.h"
 
 #ifndef va_copy
 #ifdef __va_copy
@@ -266,15 +267,12 @@ typedef uint32_t HANDLE;
 extern "C" {
 #endif
 
-void set_program_name__(const char *name, const char *version,
-                        const char *date, const char *time);
 #define set_program_name(name) \
-        set_program_name__(name, VERSION, __DATE__, __TIME__)
+        ovs_set_program_name(name, OVS_PACKAGE_VERSION)
 
 const char *get_subprogram_name(void);
 void set_subprogram_name(const char *format, ...) PRINTF_FORMAT(1, 2);
 
-const char *get_program_version(void);
 void ovs_print_version(uint8_t min_ofp, uint8_t max_ofp);
 
 NO_RETURN void out_of_memory(void);