From: Katy Feng Date: Thu, 6 Apr 2023 18:27:41 +0000 (-0700) Subject: Improve POSIX guest identification X-Git-Tag: stable-12.3.0~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a16728979d86ed78009817f1940a3ddc40b9103;p=thirdparty%2Fopen-vm-tools.git Improve POSIX guest identification 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. --- diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index f3aef0784..1e7e59fca 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -19,12 +19,12 @@ #define _GNU_SOURCE #include #include -#include #include #include #include #include #include +#include #include #include #include @@ -150,6 +150,8 @@ 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);