From 9aa82cd7e62f0da65f371fc88e342689ebf203ae Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 21 Jul 2020 12:17:32 +0200 Subject: [PATCH] lscpu: (virt) simplify hypervisor parsing Signed-off-by: Karel Zak --- sys-utils/lscpu-virt.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/sys-utils/lscpu-virt.c b/sys-utils/lscpu-virt.c index 3ffcbccb29..9acc6bfd4d 100644 --- a/sys-utils/lscpu-virt.c +++ b/sys-utils/lscpu-virt.c @@ -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, -- 2.47.3