]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Improve POSIX guest identification
authorKaty Feng <fkaty@vmware.com>
Thu, 6 Apr 2023 18:27:41 +0000 (11:27 -0700)
committerKaty Feng <fkaty@vmware.com>
Thu, 6 Apr 2023 18:27:41 +0000 (11:27 -0700)
Many Linux distros do not provide LSB information.  Instead,
they rely exclusively on the the os-release standard information.

We previously used a ranking system that rates the LSB data
(if present) against the os-release data (if present).
With the LSB data install much more rare than before, perform
a quick check for the LSB before attempting expensive operations.

This is in response to these GitHub issues:

https://github.com/vmware/open-vm-tools/issues/647
https://github.com/vmware/open-vm-tools/issues/648

Note that we cannot look just for the os-release data.  In older
Linux releases, there are mistakes or differences between the
os-release and LSB data.  We must continue to do what we do now
or risk changing the identification of older releases.

This optimization is very effective.

open-vm-tools/lib/misc/hostinfoPosix.c

index f3aef07845cab2d3f96d1ecc95d5ddbd092c37c7..1e7e59fcac90627dcd55287cbc3f33201608525c 100644 (file)
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <string.h>
 #include <ctype.h>
 #include <sys/utsname.h>
 #include <netdb.h>
 #include <fcntl.h>
+#include <unistd.h>
 #include <limits.h>
 #include <errno.h>
 #include <sys/file.h>
    MAX(sizeof SYSTEM_BITNESS_64_ARM_LINUX, \
        sizeof SYSTEM_BITNESS_64_ARM_FREEBSD))))
 
+#define LSB_RELEASE "/usr/bin/lsb_release"
+
 struct hostinfoOSVersion {
    int   hostinfoOSVersion[4];
    char *hostinfoOSVersionString;
@@ -1793,11 +1795,21 @@ HostinfoLsb(char ***args)  // OUT:
    char *lsbOutput;
    size_t fields = ARRAYSIZE(lsbFields) - 1;  // Exclude terminator
 
+   /*
+    * In recent times, an increasing number of distros do not have the
+    * LSB support installed. Perform a quick check for it and bail if
+    * it's not accessible.
+    */
+
+   if (access(LSB_RELEASE, F_OK | X_OK) == -1) {
+      return -1;
+   }
+
    /*
     * Try to get OS detailed information from the lsb_release command.
     */
 
-   lsbOutput = HostinfoGetCmdOutput("/usr/bin/lsb_release -sd 2>/dev/null");
+   lsbOutput = HostinfoGetCmdOutput(LSB_RELEASE " -sd 2>/dev/null");
 
    if (lsbOutput == NULL) {
       /*
@@ -1820,14 +1832,16 @@ HostinfoLsb(char ***args)  // OUT:
       free(lsbOutput);
 
       /* LSB Distributor */
-      lsbOutput = HostinfoGetCmdOutput("/usr/bin/lsb_release -si 2>/dev/null");
+      lsbOutput = HostinfoGetCmdOutput(LSB_RELEASE " -si 2>/dev/null");
+
       if (lsbOutput != NULL) {
          (*args)[0] = Util_SafeStrdup(HostinfoLsbRemoveQuotes(lsbOutput));
          free(lsbOutput);
       }
 
       /* LSB Release */
-      lsbOutput = HostinfoGetCmdOutput("/usr/bin/lsb_release -sr 2>/dev/null");
+      lsbOutput = HostinfoGetCmdOutput(LSB_RELEASE " -sr 2>/dev/null");
+
       if (lsbOutput != NULL) {
          (*args)[1] = Util_SafeStrdup(HostinfoLsbRemoveQuotes(lsbOutput));
          free(lsbOutput);