Skip to content

Commit

Permalink
lib: Add API to set program name and version
Browse files Browse the repository at this point in the history
Required to have reasonable logging messages.

Signed-off-by: Thomas Graf <tgraf@noironetworks.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
  • Loading branch information
Thomas Graf authored and blp committed Nov 25, 2014
1 parent 3f47a0c commit b0248b2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions 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

31 changes: 31 additions & 0 deletions 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 <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
2 changes: 1 addition & 1 deletion lib/unixctl.c
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions lib/util.c
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions lib/util.h
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b0248b2

Please sign in to comment.