]> git.proxmox.com Git - qemu-server.git/blobdiff - qmeventd/qmeventd.c
qmeventd: VMID from PID: don't fail immediately when encountering unexpected entry
[qemu-server.git] / qmeventd / qmeventd.c
index 921c0dca1607b5e9d974a039516c555ac26e7c8a..76a894cb56d1bc2ba01da9cea605cf20935bf015 100644 (file)
@@ -105,35 +105,37 @@ get_vmid_from_pid(pid_t pid)
        char *cgroup_path = strrchr(buf, ':');
        if (!cgroup_path) {
            fprintf(stderr, "unexpected cgroup entry %s\n", buf);
-           goto ret;
+           continue;
        }
        cgroup_path++;
 
-       if (strncmp(cgroup_path, "/qemu.slice", 11)) {
+       if (strncmp(cgroup_path, "/qemu.slice/", 12)) {
            continue;
        }
 
        char *vmid_start = strrchr(buf, '/');
        if (!vmid_start) {
            fprintf(stderr, "unexpected cgroup entry %s\n", buf);
-           goto ret;
+           continue;
        }
        vmid_start++;
 
        if (vmid_start[0] == '-' || vmid_start[0] == '\0') {
            fprintf(stderr, "invalid vmid in cgroup entry %s\n", buf);
-           goto ret;
+           continue;
        }
 
        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;
@@ -142,7 +144,7 @@ get_vmid_from_pid(pid_t pid)
     if (errno) {
        fprintf(stderr, "error parsing vmid for %d: %s\n", pid, strerror(errno));
     } else {
-       fprintf(stderr, "error parsing vmid for %d: no qemu.slice cgroup entry\n", pid);
+       fprintf(stderr, "error parsing vmid for %d: no matching qemu.slice cgroup entry\n", pid);
     }
 
 ret: