From: VMware, Inc <> Date: Thu, 24 Feb 2011 22:41:52 +0000 (-0800) Subject: Fix Linux tools build breakage X-Git-Tag: 2011.02.23-368700~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=441a0f386fd22585e65294db2e95ba9d9df7aa03;p=thirdparty%2Fopen-vm-tools.git Fix Linux tools build breakage Do a compile-time check instead of a run-time check for Mac OS. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/misc/hostinfoPosix.c b/open-vm-tools/lib/misc/hostinfoPosix.c index bdb389ef1..60dc11b12 100644 --- a/open-vm-tools/lib/misc/hostinfoPosix.c +++ b/open-vm-tools/lib/misc/hostinfoPosix.c @@ -440,6 +440,7 @@ Hostinfo_GetSystemBitness(void) } +#if !defined __APPLE__ /* *----------------------------------------------------------------------------- * @@ -719,6 +720,7 @@ out: return ret; } +#endif /* @@ -844,7 +846,40 @@ HostinfoOSData(void) Str_Sprintf(osNameFull, sizeof osNameFull, "%s %s", buf.sysname, buf.release); - // XXX We should use compile-time instead of run-time checks. +#if defined __APPLE__ + { + /* + * The easiest way is to invoke "system_profiler" and hope that the + * format of its unlocalized output will never change. + * + * Alternatively, we could do what system_profiler does and use the + * CFPropertyList/CFDIctionary APIs to parse + * /System/Library/CoreServices/{Server,System}Version.plist. + * + * On a MacBookPro4,1 (and possibly other models), invoking + * "system_profiler" can take several seconds: it seems to spin up the CD + * drive as a side-effect. So use "system_profiler SPSoftwareDataType" + * instead. + */ + char *sysname = HostinfoGetCmdOutput( + "/usr/sbin/system_profiler SPSoftwareDataType" + " | /usr/bin/grep 'System Version:'" + " | /usr/bin/cut -d : -f 2"); + + if (sysname) { + char *trimmed = Unicode_Trim(sysname); + + ASSERT_MEM_ALLOC(trimmed); + free(sysname); + Str_Snprintf(osNameFull, sizeof osNameFull, "%s", trimmed); + free(trimmed); + } else { + Log("%s: Failed to get output of system_profiler.\n", __FUNCTION__); + /* Fall back to returning the original osNameFull. */ + } + } +#else + // XXX Use compile-time instead of run-time checks for these as well. if (strstr(osNameFull, "Linux")) { char distro[DISTRO_BUF_SIZE]; char distroShort[DISTRO_BUF_SIZE]; @@ -975,37 +1010,8 @@ HostinfoOSData(void) Str_Snprintf(osName, sizeof osName, "%s%s", STR_OS_SOLARIS, solarisRelease); - } else if (strstr(osNameFull, "Darwin")) { - /* - * The easiest way is to invoke "system_profiler" and hope that the - * format of its unlocalized output will never change. - * - * Alternatively, we could do what system_profiler does and use the - * CFPropertyList/CFDIctionary APIs to parse - * /System/Library/CoreServices/{Server,System}Version.plist. - * - * On a MacBookPro4,1 (and possibly other models), invoking - * "system_profiler" can take several seconds: it seems to spin up the CD - * drive as a side-effect. So use "system_profiler SPSoftwareDataType" - * instead. - */ - char *sysname = HostinfoGetCmdOutput( - "/usr/sbin/system_profiler SPSoftwareDataType" - " | /usr/bin/grep 'System Version:'" - " | /usr/bin/cut -d : -f 2"); - - if (sysname) { - char *trimmed = Unicode_Trim(sysname); - - ASSERT_MEM_ALLOC(trimmed); - free(sysname); - Str_Snprintf(osNameFull, sizeof osNameFull, "%s", trimmed); - free(trimmed); - } else { - Log("%s: Failed to get output of system_profiler.\n", __FUNCTION__); - /* Fall back to returning the original osNameFull. */ - } } +#endif if (Hostinfo_GetSystemBitness() == 64) { if (strlen(osName) + sizeof STR_OS_64BIT_SUFFIX > sizeof osName) {