From: VMware, Inc <> Date: Thu, 18 Nov 2010 21:49:24 +0000 (-0800) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2010.11.17-327185~56 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1d8ecd65f904741dd713079764073fbbcb539b09;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/misc/hostType.c b/open-vm-tools/lib/misc/hostType.c index 1d42d362f..4ef0ce032 100644 --- a/open-vm-tools/lib/misc/hostType.c +++ b/open-vm-tools/lib/misc/hostType.c @@ -23,6 +23,8 @@ * code to determine the host OS type. */ +#define _GNU_SOURCE + #include #include @@ -30,12 +32,15 @@ #include "hostType.h" #include "str.h" -#if defined(VMX86_SERVER) || (defined(VMX86_VPX) && defined(linux)) +#if defined(linux) +#include #include #include #include +#if defined(VMX86_SERVER) || defined(VMX86_VPX) #include "uwvmkAPI.h" -#endif +#endif // defined(VMX86_SERVER) || defined(VMX86_VPX) +#endif // defined(linux) #define LGPFX "HOSTTYPE:" @@ -66,56 +71,65 @@ static int HostTypeOSVMKernelType(void) { -#if defined(VMX86_SERVER) || (defined(VMX86_VPX) && defined(linux)) +#if defined(linux) static int vmkernelType = -1; if (vmkernelType == -1) { - char osname[128]; - size_t osnameLength; - int kernOsTypeCtl[] = { CTL_KERN, KERN_OSTYPE }; - int rc; - - osnameLength = sizeof(osname); - rc = sysctl(kernOsTypeCtl, ARRAYSIZE(kernOsTypeCtl), - osname, &osnameLength, - 0, 0); - if (rc == 0) { - osnameLength = MAX(sizeof (osname), osnameLength); - - /* - * XXX Yes, this is backwards in order of probability now, but we - * call it only once and anyway someday it won't be backwards ... - */ - - if (! strncmp(osname, USERWORLD_SYSCTL_VISOR64_OSTYPE, - osnameLength)) { - vmkernelType = 4; - } else if (! strncmp(osname, USERWORLD_SYSCTL_KERN64_OSTYPE, - osnameLength)) { - vmkernelType = 3; - } else if (! strncmp(osname, USERWORLD_SYSCTL_VISOR_OSTYPE, - osnameLength)) { - vmkernelType = 2; - } else if (! strncmp(osname, USERWORLD_SYSCTL_KERN_OSTYPE, - osnameLength)) { - vmkernelType = 1; + if (strncmp(gnu_get_libc_release(), "vmware", 6) == 0) { +#if defined(VMX86_SERVER) || defined(VMX86_VPX) + char osname[128]; + size_t osnameLength = sizeof(osname); + int kernOsTypeCtl[] = { CTL_KERN, KERN_OSTYPE }; + + if (sysctl(kernOsTypeCtl, ARRAYSIZE(kernOsTypeCtl), + osname, &osnameLength, 0, 0) == 0) { + osnameLength = MAX(sizeof (osname), osnameLength); + + /* + * XXX Yes, this is backwards in order of probability now, but we + * call it only once and anyway someday it won't be backwards ... + */ + + if (! strncmp(osname, USERWORLD_SYSCTL_VISOR64_OSTYPE, + osnameLength)) { + vmkernelType = 4; + } else if (! strncmp(osname, USERWORLD_SYSCTL_KERN64_OSTYPE, + osnameLength)) { + vmkernelType = 3; + } else if (! strncmp(osname, USERWORLD_SYSCTL_VISOR_OSTYPE, + osnameLength)) { + vmkernelType = 2; + } else if (! strncmp(osname, USERWORLD_SYSCTL_KERN_OSTYPE, + osnameLength)) { + vmkernelType = 1; + } else { + vmkernelType = 0; + } } else { + /* + * XXX too many of the callers don't define Warning. See bug 125455 + */ + vmkernelType = 0; } - } else { +#else // defined(VMX86_SERVER) || defined(VMX86_VPX) /* - * XXX too many of the callers don't define Warning. See bug 125455 + * Only binaries part of ESX and VPX are supposed to work in userworlds. + * Hitting this assert means that you have built with incorrect PRODUCT. */ + NOT_REACHED(); +#endif // defined(VMX86_SERVER) || defined(VMX86_VPX) + } else { vmkernelType = 0; } } return (vmkernelType); -#else - /* Non-ESX builds are never running on the VMKernel. */ +#else // defined(linux) + /* Non-linux builds are never running on the VMKernel. */ return 0; -#endif +#endif // defined(linux) }