[PATCH 4/5] virsysinfo: Be more forgiving when decoding OEM strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On some systems, there are two or even more 'OEM Strings'
sections in DMI table. Here's an example of dmidecode output on
such system:

  # dmidecode -q -t 11
  OEM Strings
          String 1: Default string

  OEM Strings
          String 1: ThunderX2 System
          String 2: cavium.com
          String 3: Comanche

Now, this poses a problem, because when one tries to obtain
individual strings, they get:

  # dmidecode -q --oem-string 1
  Default string
  ThunderX2 System

  # dmidecode -q --oem-string 2
  No OEM string number 2
  cavium.com

NB, the "No OEM string number 2" is printed onto stderr and
everything else onto stdout. Oh, and trying to get OEM strings
from just one section doesn't fly:

  # dmidecode -q -H 0x1d --oem-string 2
  Options --string, --type, --handle and --dump-bin are mutually exclusive

This means two things:

1) we have no way of distinguishing OEM strings at the same index
   but in different sections,

2) because of how virSysinfoDMIDecodeOEMString() is written, we
   fail in querying OEM string that exists in one section but not
   in the others (for instance string #2 from example above).

While there's not much we can do about 1), there is something
that can be done about 2) - refine the error condition and make
the function return an error iff there's nothing on stdout and
there's something on stderr.

Resolves: https://issues.redhat.com/browse/RHEL-45952
Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virsysinfo.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index cdc2a7d87b..1fd8261dc1 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -910,9 +910,20 @@ virSysinfoDMIDecodeOEMString(size_t i,
 
     /* Unfortunately, dmidecode returns 0 even if OEM String index is out
      * of bounds, but it prints an error message in that case. Check stderr
-     * and return success/failure accordingly. */
+     * and return success/failure accordingly.
+     * To make matters worse, if there are two or more 'OEM String'
+     * sections then:
+     *
+     * a) we have no way of distinguishing them as dmidecode prints
+     *    strings from all sections,
+     * b) if one section contains a valid string, but the other doesn't,
+     *    then stdout contains the valid string and stderr contains the
+     *    error "No OEM string number X*.
+     *
+     * Let's just hope there is not many systems like that.
+     */
 
-    if (err && *err != '\0')
+    if (!(*str && **str != '\0') && err && *err != '\0')
         return -1;
 
     virStringTrimOptionalNewline(*str);
-- 
2.44.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux