[pve-devel] [PATCH v2 qemu-server 2/4] qmeventd: further improve getting VMID from PID

Fiona Ebner f.ebner at proxmox.com
Mon Jul 10 10:53:00 CEST 2023


by also expecting the ".scope" part and trying the next entry if it is
not present instead of immediately failing.

It's still unexpected to encounter such entries, so keep the log line.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---

Changes in v2:
    * Keep setting vmid to zero in the error case!
    * Still print error to indicate it's unexpected. Can potentially
      be helpful for debugging.

 qmeventd/qmeventd.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/qmeventd/qmeventd.c b/qmeventd/qmeventd.c
index 503bce69..0130103d 100644
--- a/qmeventd/qmeventd.c
+++ b/qmeventd/qmeventd.c
@@ -128,12 +128,14 @@ get_vmid_from_pid(pid_t pid)
 	errno = 0;
 	char *endptr = NULL;
 	vmid = strtoul(vmid_start, &endptr, 10);
+	if (!endptr || strncmp(endptr, ".scope", 6)) {
+	    fprintf(stderr, "unexpected cgroup entry %s\n", buf);
+	    vmid = 0;
+	    continue;
+	}
 	if (errno != 0) {
 	    fprintf(stderr, "error parsing vmid for %d: %s\n", pid, strerror(errno));
 	    vmid = 0;
-	} else if (*endptr != '.') {
-	    fprintf(stderr, "unexpected cgroup entry %s\n", buf);
-	    vmid = 0;
 	}
 
 	goto ret;
-- 
2.39.2






More information about the pve-devel mailing list