From b0248b2ac8261a282ac5504c728c04cb51086fb4 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Mon, 24 Nov 2014 12:49:01 +0100 Subject: [PATCH] lib: Add API to set program name and version Required to have reasonable logging messages. Signed-off-by: Thomas Graf Signed-off-by: Ben Pfaff --- include/openvswitch/automake.mk | 1 + include/openvswitch/util.h | 31 +++++++++++++++++++++++++++++++ lib/unixctl.c | 2 +- lib/util.c | 17 +++++++++++++---- lib/util.h | 6 ++---- 5 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 include/openvswitch/util.h diff --git a/include/openvswitch/automake.mk b/include/openvswitch/automake.mk index 5253e62dc1a..cf89f446dd4 100644 --- a/include/openvswitch/automake.mk +++ b/include/openvswitch/automake.mk @@ -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 index 00000000000..58c2b598228 --- /dev/null +++ b/include/openvswitch/util.h @@ -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 + +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 diff --git a/lib/unixctl.c b/lib/unixctl.c index 76dc933f8ce..5749293baa3 100644 --- a/lib/unixctl.c +++ b/lib/unixctl.c @@ -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 diff --git a/lib/util.c b/lib/util.c index f4d0f8de559..453ade6dc4f 100644 --- a/lib/util.c +++ b/lib/util.c @@ -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) diff --git a/lib/util.h b/lib/util.h index 2258315c636..8ef80c02731 100644 --- a/lib/util.h +++ b/lib/util.h @@ -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);