]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: (virt) simplify hypervisor parsing
authorKarel Zak <kzak@redhat.com>
Tue, 21 Jul 2020 10:17:32 +0000 (12:17 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 08:19:02 +0000 (09:19 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-virt.c

index 3ffcbccb295e21ab2f8411974bd13744fe379e0c..9acc6bfd4df48e0cfd3e9502acb56578a35dd225 100644 (file)
@@ -619,26 +619,16 @@ struct lscpu_virt *lscpu_read_virtualization(struct lscpu_cxt *cxt)
                virt->type = VIRT_TYPE_FULL;
 
                while (fgets(buf, sizeof(buf), fd) != NULL) {
-                       char *str, *p;
-
                        if (!strstr(buf, "Control Program:"))
                                continue;
                        virt->vendor = strstr(buf, "KVM") ? VIRT_VENDOR_KVM : VIRT_VENDOR_IBM;
-                       p = strchr(buf, ':');
-                       if (!p)
-                               continue;
-                       xasprintf(&str, "%s", p + 1);
-
-                       /* remove leading, trailing and repeating whitespace */
-                       while (*str == ' ')
-                               str++;
-                       virt->hypervisor = str;
-                       str += strlen(str) - 1;
-                       while ((*str == '\n') || (*str == ' '))
-                               *(str--) = '\0';
-                       while ((str = strstr(virt->hypervisor, "  ")))
-                               memmove(str, str + 1, strlen(str));
-                       break;
+                       virt->hypervisor = strchr(buf, ':');
+
+                       if (virt->hypervisor) {
+                               virt->hypervisor++;
+                               normalize_whitespace((unsigned char *) virt->hypervisor);
+                               break;
+                       }
                }
                if (virt->hypervisor)
                        virt->hypervisor = xstrdup(virt->hypervisor);
@@ -687,7 +677,7 @@ struct lscpu_virt *lscpu_read_virtualization(struct lscpu_cxt *cxt)
                }
        }
 done:
-       DBG(VIRT, ul_debugobj(virt, "virt: cpu=%s hypervisor=%s vendor=%d type=%d",
+       DBG(VIRT, ul_debugobj(virt, "virt: cpu='%s' hypervisor='%s' vendor=%d type=%d",
                                virt->cpuflag,
                                virt->hypervisor,
                                virt->vendor,