Skip to content

Commit

Permalink
ovs-vsctl: Add parent process name and ID.
Browse files Browse the repository at this point in the history
This patch forces appending "parent_process_name(PID)" when invoking
ovs-vsctl, in order to assist debugging. The patch is for Linux only.
For example:
    User adds br0 by "ovs-vsctl add-br0", the log shows:
    "ovs-vsctl (invoked by base(1528)): ovs-vsctl add-br br0"

Signed-off-by: William Tu <[email protected]>
[[email protected] made stylistic changes]
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
williamtu authored and blp committed Jan 20, 2016
1 parent 7157b6d commit 4843717
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions utilities/ovs-vsctl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2468,6 +2468,44 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands,
}
}

static char *
vsctl_parent_process_info(void)
{
#ifdef __linux__
pid_t parent_pid;
char *procfile;
struct ds s;
FILE *f;

parent_pid = getppid();
procfile = xasprintf("/proc/%d/cmdline", parent_pid);

f = fopen(procfile, "r");
if (!f) {
VLOG_WARN("%s: open failed (%s)", procfile, ovs_strerror(errno));
free(procfile);
return NULL;
}
free(procfile);

ds_init(&s);
for (;;) {
int c = getc(f);
if (!c || c == EOF) {
break;
}
ds_put_char(&s, c);
}
fclose(f);

ds_put_format(&s, " (pid %d)", parent_pid);

return ds_steal_cstr(&s);
#else
return NULL;
#endif
}

static void
do_vsctl(const char *args, struct ctl_command *commands, size_t n_commands,
struct ovsdb_idl *idl)
Expand All @@ -2481,13 +2519,21 @@ do_vsctl(const char *args, struct ctl_command *commands, size_t n_commands,
struct shash_node *node;
int64_t next_cfg = 0;
char *error = NULL;
char *ppid_info = NULL;

txn = the_idl_txn = ovsdb_idl_txn_create(idl);
if (dry_run) {
ovsdb_idl_txn_set_dry_run(txn);
}

ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
ppid_info = vsctl_parent_process_info();
if (ppid_info) {
ovsdb_idl_txn_add_comment(txn, "ovs-vsctl (invoked by %s): %s",
ppid_info, args);
free(ppid_info);
} else {
ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
}

ovs = ovsrec_open_vswitch_first(idl);
if (!ovs) {
Expand Down

0 comments on commit 4843717

Please sign in to comment.