]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsysinfo: Use more virSkipSpacesBackwards()
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 13 Mar 2018 15:03:13 +0000 (16:03 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 14 Mar 2018 16:43:40 +0000 (17:43 +0100)
Some fields reported by dmidecode have plenty of useless spaces
(in fact some have nothing but spaces). To deal with this we have
introduced virSkipSpacesBackwards() and use it in
virSysinfoParseX86Processor() and virSysinfoParseX86Memory().
However, other functions (e.g. virSysinfoParseX86Chassis()) don't
use it at all and thus we are reporting nonsense:

  <sysinfo type='smbios'>
    <chassis>
      <entry name='manufacturer'>FUJITSU</entry>
      <entry name='version'>                      </entry>
      <entry name='serial'>                </entry>
      <entry name='asset'>                                        </entry>
      <entry name='sku'>Default string</entry>
    </chassis>
  </sysinfo>

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virsysinfo.c
tests/sysinfodata/x86sysinfo.data

index 43a4c8835473a5c3bc5d23bf9d954517b7b0ac00..5795d90c7bfa1cf03d408effabdd26dd63ada067 100644 (file)
@@ -644,7 +644,8 @@ static int
 virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
 {
     int ret = -1;
-    const char *cur, *eol = NULL;
+    const char *cur;
+    char *eol = NULL;
     virSysinfoBIOSDefPtr def;
 
     if ((cur = strstr(base, "BIOS Information")) == NULL)
@@ -657,24 +658,28 @@ virSysinfoParseBIOS(const char *base, virSysinfoBIOSDefPtr *bios)
     if ((cur = strstr(base, "Vendor: ")) != NULL) {
         cur += 8;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->vendor, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Version: ")) != NULL) {
         cur += 9;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Release Date: ")) != NULL) {
         cur += 14;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->date, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "BIOS Revision: ")) != NULL) {
         cur += 15;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->release, cur, eol - cur) < 0)
             goto cleanup;
     }
@@ -697,7 +702,8 @@ static int
 virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef)
 {
     int ret = -1;
-    const char *cur, *eol = NULL;
+    const char *cur;
+    char *eol = NULL;
     virSysinfoSystemDefPtr def;
 
     if ((cur = strstr(base, "System Information")) == NULL)
@@ -710,42 +716,49 @@ virSysinfoParseX86System(const char *base, virSysinfoSystemDefPtr *sysdef)
     if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
         cur += 14;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Product Name: ")) != NULL) {
         cur += 14;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Version: ")) != NULL) {
         cur += 9;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Serial Number: ")) != NULL) {
         cur += 15;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "UUID: ")) != NULL) {
         cur += 6;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->uuid, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "SKU Number: ")) != NULL) {
         cur += 12;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Family: ")) != NULL) {
         cur += 8;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->family, cur, eol - cur) < 0)
             goto cleanup;
     }
@@ -770,7 +783,8 @@ virSysinfoParseX86BaseBoard(const char *base,
                             size_t *nbaseBoard)
 {
     int ret = -1;
-    const char *cur, *eol = NULL;
+    const char *cur;
+    char *eol = NULL;
     virSysinfoBaseBoardDefPtr boards = NULL;
     size_t nboards = 0;
     char *board_type = NULL;
@@ -787,36 +801,42 @@ virSysinfoParseX86BaseBoard(const char *base,
         if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0)
                 goto cleanup;
         }
         if ((cur = strstr(base, "Product Name: ")) != NULL) {
             cur += 14;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if (eol && VIR_STRNDUP(def->product, cur, eol - cur) < 0)
                 goto cleanup;
         }
         if ((cur = strstr(base, "Version: ")) != NULL) {
             cur += 9;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
                 goto cleanup;
         }
         if ((cur = strstr(base, "Serial Number: ")) != NULL) {
             cur += 15;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
                 goto cleanup;
         }
         if ((cur = strstr(base, "Asset Tag: ")) != NULL) {
             cur += 11;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0)
                 goto cleanup;
         }
         if ((cur = strstr(base, "Location In Chassis: ")) != NULL) {
             cur += 21;
             eol = strchr(cur, '\n');
+            virSkipSpacesBackwards(cur, &eol);
             if (eol && VIR_STRNDUP(def->location, cur, eol - cur) < 0)
                 goto cleanup;
         }
@@ -848,7 +868,8 @@ virSysinfoParseX86Chassis(const char *base,
                           virSysinfoChassisDefPtr *chassisdef)
 {
     int ret = -1;
-    const char *cur, *eol = NULL;
+    const char *cur;
+    char *eol = NULL;
     virSysinfoChassisDefPtr def;
 
     if ((cur = strstr(base, "Chassis Information")) == NULL)
@@ -861,30 +882,35 @@ virSysinfoParseX86Chassis(const char *base,
     if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
         cur += 14;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->manufacturer, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Version: ")) != NULL) {
         cur += 9;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->version, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Serial Number: ")) != NULL) {
         cur += 15;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->serial, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "Asset Tag: ")) != NULL) {
         cur += 11;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->asset, cur, eol - cur) < 0)
             goto cleanup;
     }
     if ((cur = strstr(base, "SKU Number: ")) != NULL) {
         cur += 12;
         eol = strchr(cur, '\n');
+        virSkipSpacesBackwards(cur, &eol);
         if (eol && VIR_STRNDUP(def->sku, cur, eol - cur) < 0)
             goto cleanup;
     }
index 03aa1175eef9fe461dac9ee1a11752b08e7524d0..426261041de2c9cb3575d0912bcb52c0cd9e24ca 100644 (file)
@@ -1,5 +1,5 @@
 BIOS Information
-       Vendor: LENOVO
+       Vendor: LENOVO   
        Version: 6DET62WW (3.12 )
        Release Date: 01/12/2010
        Address: 0xE0000