diff mbox series

[4/4] trace-cmd: Move find_pid_by_cid() into add_guest()

Message ID 20220428150635.789051-5-rostedt@goodmis.org (mailing list archive)
State Accepted
Headers show
Series trace-cmd: Clean ups for agent communications | expand

Commit Message

Steven Rostedt April 28, 2022, 3:06 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

To simplify the code even more, move the find_pid_by_cid() into
add_guest() to map the main pid process to the cid.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-vm.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c
index bf2b0695d09b..cabe4baffecb 100644
--- a/tracecmd/trace-vm.c
+++ b/tracecmd/trace-vm.c
@@ -86,6 +86,8 @@  static void find_tasks(struct trace_guest *guest)
 	closedir(dir);
 }
 
+static void find_pid_by_cid(struct trace_guest *guest);
+
 static struct trace_guest *add_guest(unsigned int cid, const char *name)
 {
 	struct trace_guest *guest;
@@ -103,6 +105,7 @@  static struct trace_guest *add_guest(unsigned int cid, const char *name)
 	guest->cid = cid;
 	guest->pid = -1;
 
+	find_pid_by_cid(guest);
 	find_tasks(guest);
 
 	return guest;
@@ -341,11 +344,8 @@  struct trace_guest *trace_get_guest(unsigned int cid, const char *name)
 
 	if (cid > 0) {
 		guest = get_guest_by_cid(cid);
-		if (!guest && name) {
+		if (!guest && name)
 			guest = add_guest(cid, name);
-			if (guest)
-				find_pid_by_cid(guest);
-		}
 	}
 	return guest;
 }
@@ -355,7 +355,6 @@  struct trace_guest *trace_get_guest(unsigned int cid, const char *name)
 #define VM_CID_ID	"address='"
 static void read_guest_cid(char *name)
 {
-	struct trace_guest *guest;
 	char *cmd = NULL;
 	char line[512];
 	char *cid;
@@ -377,9 +376,7 @@  static void read_guest_cid(char *name)
 		cid_id = strtol(cid + strlen(VM_CID_ID), NULL, 10);
 		if ((cid_id == INT_MIN || cid_id == INT_MAX) && errno == ERANGE)
 			continue;
-		guest = add_guest(cid_id, name);
-		if (guest)
-			find_pid_by_cid(guest);
+		add_guest(cid_id, name);
 		break;
 	}