Skip to content

Commit

Permalink
realtime: Fix parsing status file of host processes
Browse files Browse the repository at this point in the history
If the process is in the root namespace the NSPid property will only
have a single entry.
  • Loading branch information
TingPing authored and GeorgesStavracas committed Nov 26, 2024
1 parent 944cf20 commit 4e71201
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/xdp-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,29 @@ parse_status_field_pid (const char *val,
{
const char *t;

/* Takes "Pid: 12345" */
t = strrchr (val, '\t');
if (t == NULL)
return -ENOENT;
g_assert (t);

return parse_pid (t, pid);
}


static int
parse_status_field_nspid (const char *val,
pid_t *pid)
{
const char *t;

/* This is a tab separated list of namespaces.
* We only want the innermost namespace. */
t = strrchr (val, '\t');
if (t != NULL)
val = t;

return parse_pid (val, pid);
}

static pid_t
pidfd_to_pid (int fdinfo,
const int pidfd,
Expand Down Expand Up @@ -998,7 +1014,7 @@ parse_status_file (int pid_fd,

if (!strncmp (key, "NSpid", strlen ("NSpid")))
{
r = parse_status_field_pid (val, pid_out);
r = parse_status_field_nspid (val, pid_out);
have_pid = r > -1;
}
else if (!strncmp (key, "Uid", strlen ("Uid")))
Expand Down

0 comments on commit 4e71201

Please sign in to comment.