From 4e712013800a00604e7cf694c7b2d854965d5c44 Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Tue, 12 Nov 2024 16:02:04 -0600 Subject: [PATCH] realtime: Fix parsing status file of host processes If the process is in the root namespace the NSPid property will only have a single entry. --- src/xdp-utils.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/xdp-utils.c b/src/xdp-utils.c index c7f350341..30e23e1b0 100644 --- a/src/xdp-utils.c +++ b/src/xdp-utils.c @@ -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, @@ -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")))