@@ -2468,6 +2468,48 @@ run_prerequisites(struct ctl_command *commands, size_t n_commands,
}
}
+static char*
+vsctl_parent_process_info(void)
+{
+ pid_t parent_pid;
+ char *procfile;
+ char *msg_ppid;
+ char *msg;
+ struct ds s;
+ FILE *f;
+ size_t total_size = 0;
+
+#if defined(_WIN32) || defined (_WIN64)
+ return NULL;
+#endif
+
+ ds_init(&s);
+ parent_pid = getppid();
+ procfile = xasprintf("/proc/%d/cmdline", parent_pid);
+
+ f = fopen(procfile, "r");
+ while (1) {
+ size_t size;
+ char c;
+ size = fread(&c, 1, 1, f);
+ if (c == '\0' || size < 1) {
+ break;
+ }
+ ds_put_char(&s, c);
+ total_size += size;
+ }
+ fclose(f);
+
+ msg_ppid = xasprintf("(%d)", parent_pid);
+ ds_put_cstr(&s, msg_ppid);
+
+ msg = ds_steal_cstr(&s);
+ free(procfile);
+ free(msg_ppid);
+ ds_destroy(&s);
+ return msg;
+}
+
static void
do_vsctl(const char *args, struct ctl_command *commands, size_t n_commands,
struct ovsdb_idl *idl)
@@ -2481,13 +2523,22 @@ 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: %s -- comment %s",
+ args, ppid_info);
+ free(ppid_info);
+ }
+ else {
+ ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
+ }
ovs = ovsrec_open_vswitch_first(idl);
if (!ovs) {
This patch forces appending "-- comment parent_process_name(PID)" when invoking ovs-vsctl, in order to assist debugging. For example: User adds br0 by "ovs-vsctl add-br0", the log shows: "ovs-vsctl: ovs-vsctl add-br br0 -- comment bash(1528)" Signed-off-by: William Tu <u9012063@gmail.com> --- utilities/ovs-vsctl.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-)