Skip to content

Commit

Permalink
ovs-vsctl, ovn-nbctl, ovn-sbctl, vtep-ctl: Parse options before logging.
Browse files Browse the repository at this point in the history
These utilities logged the command very early, before parsing the options
or the command.  This meant that logging options (like --log-file or
-vsyslog:off) weren't considered for the purpose of logging the command.
This fixes the problem.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Justin Pettit <[email protected]>
  • Loading branch information
blp committed May 25, 2018
1 parent 2128f9b commit 15f6255
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 27 deletions.
8 changes: 3 additions & 5 deletions lib/db-ctl-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -2046,12 +2046,10 @@ ctl_default_db(void)
* database, otherwise false. (Not very smart, so it's prone to false
* positives.) */
bool
ctl_might_write_to_db(char **argv)
ctl_might_write_to_db(const struct ctl_command *commands, size_t n)
{
for (; *argv; argv++) {
const struct ctl_command_syntax *p = shash_find_data(&all_commands,
*argv);
if (p && p->mode == RW) {
for (size_t i = 0; i < n; i++) {
if (commands[i].syntax->mode == RW) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/db-ctl-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct ctl_command {
struct table *table;
};

bool ctl_might_write_to_db(char **argv);
bool ctl_might_write_to_db(const struct ctl_command *, size_t n);
const char *ctl_get_db_cmd_usage(void);

const char *ctl_list_db_tables_usage(void);
Expand Down
9 changes: 3 additions & 6 deletions ovn/utilities/ovn-nbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ main(int argc, char *argv[])
struct shash local_options;
unsigned int seqno;
size_t n_commands;
char *args;

set_program_name(argv[0]);
fatal_ignore_sigpipe();
Expand All @@ -106,16 +105,14 @@ main(int argc, char *argv[])

nbctl_cmd_init();

/* Log our arguments. This is often valuable for debugging systems. */
args = process_escape_args(argv);
VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

/* Parse command line. */
char *args = process_escape_args(argv);
shash_init(&local_options);
parse_options(argc, argv, &local_options);
commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
&n_commands);
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
Expand Down
8 changes: 3 additions & 5 deletions ovn/utilities/ovn-sbctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ main(int argc, char *argv[])
struct shash local_options;
unsigned int seqno;
size_t n_commands;
char *args;

set_program_name(argv[0]);
fatal_ignore_sigpipe();
Expand All @@ -109,15 +108,14 @@ main(int argc, char *argv[])

sbctl_cmd_init();

/* Log our arguments. This is often valuable for debugging systems. */
args = process_escape_args(argv);
VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);

/* Parse command line. */
char *args = process_escape_args(argv);
shash_init(&local_options);
parse_options(argc, argv, &local_options);
commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
&n_commands);
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
Expand Down
8 changes: 3 additions & 5 deletions utilities/ovs-vsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ main(int argc, char *argv[])
struct shash local_options;
unsigned int seqno;
size_t n_commands;
char *args;

set_program_name(argv[0]);
fatal_ignore_sigpipe();
Expand All @@ -145,15 +144,14 @@ main(int argc, char *argv[])

vsctl_cmd_init();

/* Log our arguments. This is often valuable for debugging systems. */
args = process_escape_args(argv);
VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);

/* Parse command line. */
char *args = process_escape_args(argv);
shash_init(&local_options);
parse_options(argc, argv, &local_options);
commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
&n_commands);
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
Expand Down
8 changes: 3 additions & 5 deletions vtep/vtep-ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ main(int argc, char *argv[])
struct shash local_options;
unsigned int seqno;
size_t n_commands;
char *args;

set_program_name(argv[0]);
fatal_ignore_sigpipe();
Expand All @@ -108,15 +107,14 @@ main(int argc, char *argv[])

vtep_ctl_cmd_init();

/* Log our arguments. This is often valuable for debugging systems. */
args = process_escape_args(argv);
VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);

/* Parse command line. */
char *args = process_escape_args(argv);
shash_init(&local_options);
parse_options(argc, argv, &local_options);
commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
&n_commands);
VLOG(ctl_might_write_to_db(commands, n_commands) ? VLL_INFO : VLL_DBG,
"Called as %s", args);

if (timeout) {
time_alarm(timeout);
Expand Down

0 comments on commit 15f6255

Please sign in to comment.