[PATCH 2/5] virsysinfo: Trim newline when decoding OEM strings

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

 



dmidecode always puts a newline character at the end of each
OEM string it prints. It's the dmi_oem_strings() function [1] that
iterates over strings and calls pr_attr() over each one which
puts "\n" at the end, unconditionally [2[.

Since it's not part of the string though, trim it.

1: https://git.savannah.nongnu.org/cgit/dmidecode.git/tree/dmidecode.c#n2431
2: https://git.savannah.nongnu.org/cgit/dmidecode.git/tree/dmioutput.c#n63

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virsysinfo.c | 2 ++
 tests/sysinfotest.c   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 0d9083c891..cdc2a7d87b 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -915,6 +915,8 @@ virSysinfoDMIDecodeOEMString(size_t i,
     if (err && *err != '\0')
         return -1;
 
+    virStringTrimOptionalNewline(*str);
+
     return 0;
 }
 
diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c
index 287c40c6f9..09cfe6fa45 100644
--- a/tests/sysinfotest.c
+++ b/tests/sysinfotest.c
@@ -66,7 +66,7 @@ testDMIDecodeDryRun(const char *const*args G_GNUC_UNUSED,
         if (STREQ(args[3], "3")) {
             *output = g_strdup("Ha ha ha try parsing\\n\n"
                                "      String 3: this correctly\n"
-                               "      String 4:then");
+                               "      String 4:then\n");
         } else {
             *error = g_strdup_printf("No OEM string number %s", args[3]);
             *status = EXIT_FAILURE;
-- 
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