Skip to content

Commit

Permalink
command-line: add ovs_cmdl_ prefix
Browse files Browse the repository at this point in the history
The coding style guidelines include the following:

  - Pick a unique name prefix (ending with an underscore) for each
    module, and apply that prefix to all of that module's externally
    visible names.  Names of macro parameters, struct and union members,
    and parameters in function prototypes are not considered externally
    visible for this purpose.

This patch adds the new prefix to the externally visible names.  This
makes it a bit more obvious what code is coming from common command
line handling code.

Signed-off-by: Russell Bryant <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
russellb authored and blp committed Mar 16, 2015
1 parent 9e0fa1f commit 5f38375
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 100 deletions.
26 changes: 13 additions & 13 deletions lib/command-line.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ VLOG_DEFINE_THIS_MODULE(command_line);
* passed to getopt() with the corresponding short options. The caller is
* responsible for freeing the string. */
char *
long_options_to_short_options(const struct option options[])
ovs_cmdl_long_options_to_short_options(const struct option options[])
{
char short_options[UCHAR_MAX * 3 + 1];
char *p = short_options;
Expand All @@ -52,15 +52,15 @@ long_options_to_short_options(const struct option options[])
return xstrdup(short_options);
}

/* Given the 'struct command' array, prints the usage of all commands. */
/* Given the 'struct ovs_cmdl_command' array, prints the usage of all commands. */
void
print_commands(const struct command commands[])
ovs_cmdl_print_commands(const struct ovs_cmdl_command commands[])
{
struct ds ds = DS_EMPTY_INITIALIZER;

ds_put_cstr(&ds, "The available commands are:\n");
for (; commands->name; commands++) {
const struct command *c = commands;
const struct ovs_cmdl_command *c = commands;
ds_put_format(&ds, " %-23s %s\n", c->name, c->usage ? c->usage : "");
}
printf("%s", ds.string);
Expand All @@ -69,7 +69,7 @@ print_commands(const struct command commands[])

/* Given the GNU-style options in 'options', prints all options. */
void
print_options(const struct option options[])
ovs_cmdl_print_options(const struct option options[])
{
struct ds ds = DS_EMPTY_INITIALIZER;

Expand All @@ -94,9 +94,9 @@ print_options(const struct option options[])
* Command-line options should be stripped off, so that a typical invocation
* looks like "run_command(argc - optind, argv + optind, my_commands);". */
void
run_command(int argc, char *argv[], const struct command commands[])
ovs_cmdl_run_command(int argc, char *argv[], const struct ovs_cmdl_command commands[])
{
const struct command *p;
const struct ovs_cmdl_command *p;

if (argc < 1) {
ovs_fatal(0, "missing command name; use --help for help");
Expand Down Expand Up @@ -150,7 +150,7 @@ static char *saved_proctitle OVS_GUARDED_BY(proctitle_mutex);
* before anything else, period, at the very beginning of program
* execution. */
void
proctitle_init(int argc, char **argv)
ovs_cmdl_proctitle_init(int argc, char **argv)
{
int i;

Expand Down Expand Up @@ -190,7 +190,7 @@ proctitle_init(int argc, char **argv)
/* Changes the name of the process, as shown by "ps", to the program name
* followed by 'format', which is formatted as if by printf(). */
void
proctitle_set(const char *format, ...)
ovs_cmdl_proctitle_set(const char *format, ...)
{
va_list args;
int n;
Expand Down Expand Up @@ -225,7 +225,7 @@ proctitle_set(const char *format, ...)

/* Restores the process's original command line, as seen by "ps". */
void
proctitle_restore(void)
ovs_cmdl_proctitle_restore(void)
{
ovs_mutex_lock(&proctitle_mutex);
if (saved_proctitle) {
Expand All @@ -239,20 +239,20 @@ proctitle_restore(void)
/* Stubs that don't do anything on non-Linux systems. */

void
proctitle_init(int argc OVS_UNUSED, char **argv OVS_UNUSED)
ovs_cmdl_proctitle_init(int argc OVS_UNUSED, char **argv OVS_UNUSED)
{
}

#if !(defined(__FreeBSD__) || defined(__NetBSD__))
/* On these platforms we #define this to setproctitle. */
void
proctitle_set(const char *format OVS_UNUSED, ...)
ovs_cmdl_proctitle_set(const char *format OVS_UNUSED, ...)
{
}
#endif

void
proctitle_restore(void)
ovs_cmdl_proctitle_restore(void)
{
}
#endif /* !__linux__ */
18 changes: 9 additions & 9 deletions lib/command-line.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@

struct option;

struct command {
struct ovs_cmdl_command {
const char *name;
const char *usage;
int min_args;
int max_args;
void (*handler)(int argc, char *argv[]);
};

char *long_options_to_short_options(const struct option *options);
void print_options(const struct option *options);
void print_commands(const struct command *commands);
void run_command(int argc, char *argv[], const struct command[]);
char *ovs_cmdl_long_options_to_short_options(const struct option *options);
void ovs_cmdl_print_options(const struct option *options);
void ovs_cmdl_print_commands(const struct ovs_cmdl_command *commands);
void ovs_cmdl_run_command(int argc, char *argv[], const struct ovs_cmdl_command[]);

void proctitle_init(int argc, char **argv);
void ovs_cmdl_proctitle_init(int argc, char **argv);
#if defined(__FreeBSD__) || defined(__NetBSD__)
#define proctitle_set setproctitle
#define ovs_cmdl_proctitle_set setproctitle
#else
void proctitle_set(const char *, ...)
void ovs_cmdl_proctitle_set(const char *, ...)
OVS_PRINTF_FORMAT(1, 2);
#endif
void proctitle_restore(void);
void ovs_cmdl_proctitle_restore(void);

#endif /* command-line.h */
6 changes: 3 additions & 3 deletions lib/daemon-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ monitor_daemon(pid_t daemon_pid)
int retval;
int status;

proctitle_set("monitoring pid %lu (%s)",
(unsigned long int) daemon_pid, status_msg);
ovs_cmdl_proctitle_set("monitoring pid %lu (%s)",
(unsigned long int) daemon_pid, status_msg);

if (child_ready) {
do {
Expand Down Expand Up @@ -399,7 +399,7 @@ monitor_daemon(pid_t daemon_pid)
free(status_msg);

/* Running in new daemon process. */
proctitle_restore();
ovs_cmdl_proctitle_restore();
set_subprogram_name("");
}

Expand Down
4 changes: 2 additions & 2 deletions ovsdb/ovsdb-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ main(int argc, char *argv[])
const char *database;
struct jsonrpc *rpc;

proctitle_init(argc, argv);
ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
parse_options(argc, argv);
fatal_ignore_sigpipe();
Expand Down Expand Up @@ -183,7 +183,7 @@ parse_options(int argc, char *argv[])
TABLE_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
char *short_options = long_options_to_short_options(long_options);
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);

for (;;) {
int c;
Expand Down
4 changes: 2 additions & 2 deletions ovsdb/ovsdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ main(int argc, char *argv[])
char *error;
int i;

proctitle_init(argc, argv);
ovs_cmdl_proctitle_init(argc, argv);
set_program_name(argv[0]);
service_start(&argc, &argv);
fatal_ignore_sigpipe();
Expand Down Expand Up @@ -1242,7 +1242,7 @@ parse_options(int *argcp, char **argvp[],
{"ca-cert", required_argument, NULL, 'C'},
{NULL, 0, NULL, 0},
};
char *short_options = long_options_to_short_options(long_options);
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
int argc = *argcp;
char **argv = *argvp;

Expand Down
14 changes: 7 additions & 7 deletions ovsdb/ovsdb-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
/* -m, --more: Verbosity level for "show-log" command output. */
static int show_log_verbosity;

static const struct command *get_all_commands(void);
static const struct ovs_cmdl_command *get_all_commands(void);

OVS_NO_RETURN static void usage(void);
static void parse_options(int argc, char *argv[]);
Expand All @@ -58,7 +58,7 @@ main(int argc, char *argv[])
set_program_name(argv[0]);
parse_options(argc, argv);
fatal_ignore_sigpipe();
run_command(argc - optind, argv + optind, get_all_commands());
ovs_cmdl_run_command(argc - optind, argv + optind, get_all_commands());
return 0;
}

Expand All @@ -73,7 +73,7 @@ parse_options(int argc, char *argv[])
{"version", no_argument, NULL, 'V'},
{NULL, 0, NULL, 0},
};
char *short_options = long_options_to_short_options(long_options);
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);

for (;;) {
int c;
Expand All @@ -92,7 +92,7 @@ parse_options(int argc, char *argv[])
usage();

case 'o':
print_options(long_options);
ovs_cmdl_print_options(long_options);
exit(EXIT_SUCCESS);

case 'V':
Expand Down Expand Up @@ -566,10 +566,10 @@ do_help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
static void
do_list_commands(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
print_commands(get_all_commands());
ovs_cmdl_print_commands(get_all_commands());
}

static const struct command all_commands[] = {
static const struct ovs_cmdl_command all_commands[] = {
{ "create", "[db [schema]]", 0, 2, do_create },
{ "compact", "[db [dst]]", 0, 2, do_compact },
{ "convert", "[db [schema [dst]]]", 0, 3, do_convert },
Expand All @@ -586,7 +586,7 @@ static const struct command all_commands[] = {
{ NULL, NULL, 0, 0, NULL },
};

static const struct command *get_all_commands(void)
static const struct ovs_cmdl_command *get_all_commands(void)
{
return all_commands;
}
14 changes: 7 additions & 7 deletions tests/ovstest.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
#include "ovstest.h"
#include "util.h"

static struct command *commands = NULL;
static struct ovs_cmdl_command *commands = NULL;
static size_t n_commands = 0;
static size_t allocated_commands = 0;

static void
add_command(struct command *cmd)
add_command(struct ovs_cmdl_command *cmd)
{
const struct command nil = {NULL, NULL, 0, 0, NULL};
const struct ovs_cmdl_command nil = {NULL, NULL, 0, 0, NULL};

while (n_commands + 1 >= allocated_commands) {
commands = x2nrealloc(commands, &allocated_commands,
Expand Down Expand Up @@ -62,7 +62,7 @@ flush_help_string(struct ds *ds)
static void
help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
const struct command *p;
const struct ovs_cmdl_command *p;
struct ds test_names = DS_EMPTY_INITIALIZER;
const int linesize = 70;

Expand All @@ -86,15 +86,15 @@ help(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
static void
add_top_level_commands(void)
{
struct command help_cmd = {"--help", NULL, 0, 0, help};
struct ovs_cmdl_command help_cmd = {"--help", NULL, 0, 0, help};

add_command(&help_cmd);
}

void
ovstest_register(const char *test_name, ovstest_func f)
{
struct command test_cmd;
struct ovs_cmdl_command test_cmd;

test_cmd.name = test_name;
test_cmd.usage = NULL;
Expand Down Expand Up @@ -125,7 +125,7 @@ main(int argc, char *argv[])

add_top_level_commands();
if (argc > 1) {
run_command(argc - 1, argv + 1, commands);
ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}
cleanup();

Expand Down
4 changes: 2 additions & 2 deletions tests/test-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ run_benchmarks(int argc OVS_UNUSED, char *argv[])
printf("\n");
}

static const struct command commands[] = {
static const struct ovs_cmdl_command commands[] = {
{"check", NULL, 0, 0, run_tests},
{"benchmark", NULL, 1, 1, run_benchmarks},
{NULL, NULL, 0, 0, NULL},
Expand All @@ -158,7 +158,7 @@ static void
test_bitmap_main(int argc, char *argv[])
{
set_program_name(argv[0]);
run_command(argc - 1, argv + 1, commands);
ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}

OVSTEST_REGISTER("test-bitmap", test_bitmap_main);
4 changes: 2 additions & 2 deletions tests/test-classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ test_minimask_combine(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
minimask_destroy(&minicatchall);
}

static const struct command commands[] = {
static const struct ovs_cmdl_command commands[] = {
/* Classifier tests. */
{"empty", NULL, 0, 0, test_empty},
{"destroy-null", NULL, 0, 0, test_destroy_null},
Expand All @@ -1424,7 +1424,7 @@ test_classifier_main(int argc, char *argv[])
{
set_program_name(argv[0]);
init_values();
run_command(argc - 1, argv + 1, commands);
ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}

OVSTEST_REGISTER("test-classifier", test_classifier_main);
4 changes: 2 additions & 2 deletions tests/test-cmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ benchmark_hmap(void)
free(elements);
}

static const struct command commands[] = {
static const struct ovs_cmdl_command commands[] = {
{"check", NULL, 0, 1, run_tests},
{"benchmark", NULL, 3, 4, run_benchmarks},
{NULL, NULL, 0, 0, NULL},
Expand All @@ -646,7 +646,7 @@ static void
test_cmap_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
{
set_program_name(argv[0]);
run_command(argc - optind, argv + optind, commands);
ovs_cmdl_run_command(argc - optind, argv + optind, commands);
}

OVSTEST_REGISTER("test-cmap", test_cmap_main);
4 changes: 2 additions & 2 deletions tests/test-heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ test_heap_raw_delete(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
}
}

static const struct command commands[] = {
static const struct ovs_cmdl_command commands[] = {
{ "insert-delete-same-order", NULL, 0, 0,
test_heap_insert_delete_same_order, },
{ "insert-delete-reverse-order", NULL, 0, 0,
Expand All @@ -482,7 +482,7 @@ test_heap_main(int argc, char *argv[])
{
set_program_name(argv[0]);

run_command(argc - 1, argv + 1, commands);
ovs_cmdl_run_command(argc - 1, argv + 1, commands);
}

OVSTEST_REGISTER("test-heap", test_heap_main);
Loading

0 comments on commit 5f38375

Please sign in to comment.