@@ -3215,38 +3215,6 @@ static int do_accept(int sd)
return -1;
}
-/* Find all the tasks associated with the guest pid */
-static void find_tasks(struct trace_guest *guest)
-{
- struct dirent *dent;
- char *path;
- DIR *dir;
- int ret;
- int tasks = 0;
-
- ret = asprintf(&path, "/proc/%d/task", guest->pid);
- if (ret < 0)
- return;
-
- dir = opendir(path);
- free(path);
- if (!dir)
- return;
-
- while ((dent = readdir(dir))) {
- int *pids;
- if (!(dent->d_type == DT_DIR && is_digits(dent->d_name)))
- continue;
- pids = realloc(guest->task_pids, sizeof(int) * (tasks + 2));
- if (!pids)
- break;
- pids[tasks++] = strtol(dent->d_name, NULL, 0);
- pids[tasks] = -1;
- guest->task_pids = pids;
- }
- closedir(dir);
-}
-
static char *parse_guest_name(char *gname, int *cid, int *port,
struct addrinfo **res)
{
@@ -3287,9 +3255,6 @@ static char *parse_guest_name(char *gname, int *cid, int *port,
guest = trace_get_guest(*cid, gname);
if (guest) {
*cid = guest->cid;
- /* Mapping not found, search for them */
- if (!guest->cpu_pid)
- find_tasks(guest);
return guest->name;
}
@@ -54,6 +54,38 @@ bool trace_have_guests_pid(void)
return true;
}
+/* Find all the tasks associated with the guest pid */
+static void find_tasks(struct trace_guest *guest)
+{
+ struct dirent *dent;
+ char *path;
+ DIR *dir;
+ int ret;
+ int tasks = 0;
+
+ ret = asprintf(&path, "/proc/%d/task", guest->pid);
+ if (ret < 0)
+ return;
+
+ dir = opendir(path);
+ free(path);
+ if (!dir)
+ return;
+
+ while ((dent = readdir(dir))) {
+ int *pids;
+ if (!(dent->d_type == DT_DIR && is_digits(dent->d_name)))
+ continue;
+ pids = realloc(guest->task_pids, sizeof(int) * (tasks + 2));
+ if (!pids)
+ break;
+ pids[tasks++] = strtol(dent->d_name, NULL, 0);
+ pids[tasks] = -1;
+ guest->task_pids = pids;
+ }
+ closedir(dir);
+}
+
static struct trace_guest *add_guest(unsigned int cid, const char *name)
{
struct trace_guest *guest;
@@ -71,6 +103,8 @@ static struct trace_guest *add_guest(unsigned int cid, const char *name)
guest->cid = cid;
guest->pid = -1;
+ find_tasks(guest);
+
return guest;
}