INFO_MEMORY,
INFO_IPADDRESS_V2,
INFO_IPADDRESS_V3,
- INFO_OS_STRUCTURED,
+ INFO_OS_DETAILED,
INFO_MAX
} GuestInfoType;
#define HOSTINFO_STRUCT_HEADER_VERSION 1
/*
- * This struct is used to build a structured OS data. The structured data will
+ * This struct is used to build a detailed OS data. The detailed OS data will
* be composed of two parts. The first part is the header and the second part
- * will be a structured string that is appended to this header in memory.
+ * will be a string that is appended to this header in memory.
*/
-typedef struct HostinfoStructuredHeader {
+typedef struct HostinfoDetailedDataHeader {
uint32 version;
char shortName[MAX_OS_NAME_LEN + 1];
char fullName[MAX_OS_FULLNAME_LEN + 1];
-} HostinfoStructuredHeader;
+} HostinfoDetailedDataHeader;
-char *Hostinfo_NameGet(void); // Don't free result
-char *Hostinfo_HostName(void); // free result
-char *Hostinfo_GetOSName(void); // free result
-char *Hostinfo_GetOSGuestString(void); // free result
-char *Hostinfo_GetOSStructuredString(void); // free result
+char *Hostinfo_NameGet(void); // Don't free result
+char *Hostinfo_HostName(void); // free result
+char *Hostinfo_GetOSName(void); // free result
+char *Hostinfo_GetOSGuestString(void); // free result
+char *Hostinfo_GetOSDetailedData(void); // free result
void Hostinfo_MachineID(uint32 *hostNameHash,
uint64 *hostHardwareID);
* HostinfoOSData caches its returned value.
*/
-volatile Bool HostinfoOSNameCacheValid = FALSE;
-char HostinfoCachedOSName[MAX_OS_NAME_LEN];
-char HostinfoCachedOSFullName[MAX_OS_FULLNAME_LEN];
-char HostinfoCachedStructuredString[MAX_STRUCTURED_STRING_LEN];
+volatile Bool hostinfoCacheValid = FALSE;
+char hostinfoCachedOSName[MAX_OS_NAME_LEN];
+char hostinfoCachedOSFullName[MAX_OS_FULLNAME_LEN];
+char hostinfoCachedDetailedData[MAX_DETAILED_STRING_LEN];
#if defined(__i386__) || defined(__x86_64__)
Hostinfo_GetOSName(void)
{
char *name;
- Bool data = HostinfoOSNameCacheValid ? TRUE : HostinfoOSData();
+ Bool data = hostinfoCacheValid ? TRUE : HostinfoOSData();
if (data) {
- name = Util_SafeStrdup(HostinfoCachedOSFullName);
+ name = Util_SafeStrdup(hostinfoCachedOSFullName);
} else {
name = NULL;
}
Hostinfo_GetOSGuestString(void)
{
char *name;
- Bool data = HostinfoOSNameCacheValid ? TRUE : HostinfoOSData();
+ Bool data = hostinfoCacheValid ? TRUE : HostinfoOSData();
if (data) {
- name = Util_SafeStrdup(HostinfoCachedOSName);
+ name = Util_SafeStrdup(hostinfoCachedOSName);
} else {
name = NULL;
}
/*
*-----------------------------------------------------------------------------
*
- * Hostinfo_GetOSStructuredString --
+ * Hostinfo_GetOSDetailedData --
*
- * Query the operating system and build a string of property list
- * containing detailed information about the guest OS. The returned string
- * is written into the VM's .vmx file
+ * Query the operating system and build a property list containing
+ * detailed information about the guest OS.
*
* Return value:
* NULL Unable to obtain the structured string.
- * !NULL The structured string. The caller is responsible for freeing it.
+ * !NULL The detailed data string. The caller must free it.
*
* Side effects:
* Memory is allocated.
*/
char *
-Hostinfo_GetOSStructuredString(void)
+Hostinfo_GetOSDetailedData(void)
{
- char *structuredString;
- Bool data = HostinfoOSNameCacheValid ? TRUE : HostinfoOSData();
+ char *detailedData;
+ Bool data = hostinfoCacheValid ? TRUE : HostinfoOSData();
if (data) {
- structuredString = Util_SafeStrdup(HostinfoCachedStructuredString);
+ detailedData = Util_SafeStrdup(hostinfoCachedDetailedData);
} else {
- structuredString = NULL;
+ detailedData = NULL;
}
- return structuredString;
+ return detailedData;
}
#define MAX_OS_NAME_LEN 128
#define MAX_OS_FULLNAME_LEN 512
-#define MAX_STRUCTURED_FIELD_LEN 1024
+#define MAX_DETAILED_FIELD_LEN 1024
-#define STRUCTURED_STRING_DELIMITER " "
+#define DETAILED_STRING_DELIMITER " "
/*
typedef struct {
char *name;
- char value[MAX_STRUCTURED_FIELD_LEN];
-} StructuredField;
+ char value[MAX_DETAILED_FIELD_LEN];
+} DetailedDataField;
/* Must be sorted. Keep in same ordering as structuredFields */
typedef enum {
FAMILY_NAME,
KERNEL_VERSION,
PRETTY_NAME
-} StructuredFieldType;
+} DetailedDataFieldType;
/*
* Must be sorted. Keep in same ordering as StructuredFieldType. Defined in
* hostinfoPosix.c
*/
-extern StructuredField structuredFields[];
+extern DetailedDataField detailedDataFields[];
-#define MAX_STRUCTURED_STRING_LEN MAX_STRUCTURED_FIELD_LEN * 10
+#define MAX_DETAILED_STRING_LEN (10 * MAX_DETAILED_FIELD_LEN)
-extern volatile Bool HostinfoOSNameCacheValid;
-extern char HostinfoCachedOSName[MAX_OS_NAME_LEN];
-extern char HostinfoCachedOSFullName[MAX_OS_FULLNAME_LEN];
-extern char HostinfoCachedStructuredString[MAX_STRUCTURED_STRING_LEN];
+extern volatile Bool hostinfoCacheValid;
+extern char hostinfoCachedOSName[MAX_OS_NAME_LEN];
+extern char hostinfoCachedOSFullName[MAX_OS_FULLNAME_LEN];
+extern char hostinfoCachedDetailedData[MAX_DETAILED_STRING_LEN];
/*
* Global functions
};
#endif
-/* Must be sorted. Keep in the same ordering as StructuredFieldType */
-StructuredField structuredFields[] = {
+/* Must be sorted. Keep in the same ordering as DetailedDataFieldType */
+DetailedDataField detailedDataFields[] = {
{ "bitness", "" }, // "32" or "64"
{ "buildNumber", "" }, // Present for MacOS and some Linux distros.
{ "distroName", "" }, // Defaults to uname -s
while (Atomic_ReadWrite(&mutex, 1)); // Spinlock.
- if (!HostinfoOSNameCacheValid) {
- Str_Strcpy(HostinfoCachedOSName, osName, sizeof HostinfoCachedOSName);
- Str_Strcpy(HostinfoCachedOSFullName, osNameFull,
- sizeof HostinfoCachedOSFullName);
- HostinfoOSNameCacheValid = TRUE;
+ if (!hostinfoCacheValid) {
+ Str_Strcpy(hostinfoCachedOSName, osName, sizeof hostinfoCachedOSName);
+ Str_Strcpy(hostinfoCachedOSFullName, osNameFull,
+ sizeof hostinfoCachedOSFullName);
+ hostinfoCacheValid = TRUE;
}
Atomic_Write(&mutex, 0); // unlock
/*
*-----------------------------------------------------------------------------
*
- * HostinfoOSStructuredString --
+ * HostinfoOSDetailedData --
*
- * Builds, escapes, and stores the structured string into the cache.
+ * Builds, escapes, and stores the detailed data into the cache.
*
* Return value:
* TRUE Success
*/
static void
-HostinfoOSStructuredString(void)
+HostinfoOSDetailedData(void)
{
- StructuredField *field;
+ DetailedDataField *field;
/* Clear the string cache */
- memset(HostinfoCachedStructuredString, '\0',
- sizeof HostinfoCachedStructuredString);
+ memset(hostinfoCachedDetailedData, '\0',
+ sizeof hostinfoCachedDetailedData);
- for (field = structuredFields; field->name != NULL; field++) {
+ for (field = detailedDataFields; field->name != NULL; field++) {
if (field->value[0] != '\0') {
/* Account for the escape and NUL char */
int len;
const char *c;
- char escapedString[2 * MAX_STRUCTURED_FIELD_LEN + 1];
- char fieldString[MAX_STRUCTURED_FIELD_LEN];
+ char escapedString[2 * MAX_DETAILED_FIELD_LEN + 1];
+ char fieldString[MAX_DETAILED_FIELD_LEN];
uint32 i = 0;
/* Escape single quotes and back slashes in the value. */
if (len == -1) {
Warning("%s: Error: structured info field too large\n",
__FUNCTION__);
- memset(HostinfoCachedStructuredString, '\0',
- sizeof HostinfoCachedStructuredString);
+ memset(hostinfoCachedDetailedData, '\0',
+ sizeof hostinfoCachedDetailedData);
return;
}
- Str_Strcat(HostinfoCachedStructuredString, fieldString,
- sizeof HostinfoCachedStructuredString);
+ Str_Strcat(hostinfoCachedDetailedData, fieldString,
+ sizeof hostinfoCachedDetailedData);
/* Add delimiter between properties */
if ((field + 1)->name != NULL) {
- Str_Strcat(HostinfoCachedStructuredString,
- STRUCTURED_STRING_DELIMITER,
- sizeof HostinfoCachedStructuredString);
+ Str_Strcat(hostinfoCachedDetailedData,
+ DETAILED_STRING_DELIMITER,
+ sizeof hostinfoCachedDetailedData);
}
}
}
}
}
- Str_Strcpy(structuredFields[DISTRO_NAME].value, productName,
- sizeof structuredFields[DISTRO_NAME].value);
- Str_Strcpy(structuredFields[DISTRO_VERSION].value, productVersion,
- sizeof structuredFields[DISTRO_VERSION].value);
- Str_Strcpy(structuredFields[BUILD_NUMBER].value, productBuildVersion,
- sizeof structuredFields[BUILD_NUMBER].value);
+ Str_Strcpy(detailedDataFields[DISTRO_NAME].value, productName,
+ sizeof detailedDataFields[DISTRO_NAME].value);
+ Str_Strcpy(detailedDataFields[DISTRO_VERSION].value, productVersion,
+ sizeof detailedDataFields[DISTRO_VERSION].value);
+ Str_Strcpy(detailedDataFields[BUILD_NUMBER].value, productBuildVersion,
+ sizeof detailedDataFields[BUILD_NUMBER].value);
if (haveVersion) {
len = Str_Snprintf(osNameFull, sizeof osNameFull,
HostinfoReadDistroFile(TRUE, fileName, &osReleaseFields[3],
sizeof distroBuild, distroBuild);
- Str_Strcpy(structuredFields[PRETTY_NAME].value, distro,
- sizeof structuredFields[PRETTY_NAME].value);
- Str_Strcpy(structuredFields[DISTRO_NAME].value, distroName,
- sizeof structuredFields[DISTRO_NAME].value);
- Str_Strcpy(structuredFields[BUILD_NUMBER].value, distroBuild,
- sizeof structuredFields[BUILD_NUMBER].value);
- Str_Strcpy(structuredFields[DISTRO_VERSION].value, distroRelease,
- sizeof structuredFields[DISTRO_VERSION].value);
+ Str_Strcpy(detailedDataFields[PRETTY_NAME].value, distro,
+ sizeof detailedDataFields[PRETTY_NAME].value);
+ Str_Strcpy(detailedDataFields[DISTRO_NAME].value, distroName,
+ sizeof detailedDataFields[DISTRO_NAME].value);
+ Str_Strcpy(detailedDataFields[BUILD_NUMBER].value, distroBuild,
+ sizeof detailedDataFields[BUILD_NUMBER].value);
+ Str_Strcpy(detailedDataFields[DISTRO_VERSION].value, distroRelease,
+ sizeof detailedDataFields[DISTRO_VERSION].value);
return success;
}
}
if (success) {
- Str_Strcpy(structuredFields[DISTRO_NAME].value, distroName,
- sizeof structuredFields[DISTRO_NAME].value);
- Str_Strcpy(structuredFields[DISTRO_VERSION].value, distroRelease,
- sizeof structuredFields[DISTRO_VERSION].value);
- Str_Strcpy(structuredFields[PRETTY_NAME].value, distroDescription,
- sizeof structuredFields[PRETTY_NAME].value);
+ Str_Strcpy(detailedDataFields[DISTRO_NAME].value, distroName,
+ sizeof detailedDataFields[DISTRO_NAME].value);
+ Str_Strcpy(detailedDataFields[DISTRO_VERSION].value, distroRelease,
+ sizeof detailedDataFields[DISTRO_VERSION].value);
+ Str_Strcpy(detailedDataFields[PRETTY_NAME].value, distroDescription,
+ sizeof detailedDataFields[PRETTY_NAME].value);
}
return success;
return FALSE;
}
- Str_Strcpy(structuredFields[FAMILY_NAME].value, buf.sysname,
- sizeof structuredFields[FAMILY_NAME].value);
- Str_Strcpy(structuredFields[KERNEL_VERSION].value, buf.release,
- sizeof structuredFields[KERNEL_VERSION].value);
+ Str_Strcpy(detailedDataFields[FAMILY_NAME].value, buf.sysname,
+ sizeof detailedDataFields[FAMILY_NAME].value);
+ Str_Strcpy(detailedDataFields[KERNEL_VERSION].value, buf.release,
+ sizeof detailedDataFields[KERNEL_VERSION].value);
/* Default distro name is set to uname's sysname field */
- Str_Strcpy(structuredFields[DISTRO_NAME].value, buf.sysname,
- sizeof structuredFields[DISTRO_NAME].value);
+ Str_Strcpy(detailedDataFields[DISTRO_NAME].value, buf.sysname,
+ sizeof detailedDataFields[DISTRO_NAME].value);
#if defined(USERWORLD) // ESXi
bitness = "64";
#else
bitness = (Hostinfo_GetSystemBitness() == 64) ? "64" : "32";
#endif
- Str_Strcpy(structuredFields[BITNESS].value, bitness,
- sizeof structuredFields[BITNESS].value);
+ Str_Strcpy(detailedDataFields[BITNESS].value, bitness,
+ sizeof detailedDataFields[BITNESS].value);
#if defined(USERWORLD) // ESXi
success = HostinfoESX(&buf);
#endif
/* Build structured string */
- HostinfoOSStructuredString();
+ HostinfoOSDetailedData();
return success;
}
typedef struct _GuestInfoCache {
/* Stores values of all key-value pairs. */
- char *value[INFO_MAX];
- HostinfoStructuredHeader *structuredOSInfo;
- NicInfoV3 *nicInfo;
- GuestDiskInfo *diskInfo;
- NicInfoMethod method;
+ char *value[INFO_MAX];
+ HostinfoDetailedDataHeader *detailedData;
+ NicInfoV3 *nicInfo;
+ GuestDiskInfo *diskInfo;
+ NicInfoMethod method;
} GuestInfoCache;
int guestInfoStatsInterval = 0;
/*
- * Structured guest OS identification data sending. Reset on channel reset
- * (e.g. vMotion, suspend-resume, snapshot).
+ * Detailed guest OS data sending. Reset on channel reset.
*/
-static Bool gSendStructuredOsInfo = TRUE;
+static Bool gSendDetailedGosData = TRUE;
/**
* GuestInfo gather loop timeout source.
/*
******************************************************************************
- * GuestInfoStructuredInfoIsEqual --
+ * GuestInfoDetailedDataIsEqual --
*
- * Compares two HostinfoStructuredHeader and the structured string that
+ * Compares two HostinfoDetailedDataHeader and the structured string that
* follows each header.
*
* @returns True if equal
*/
static Bool
-GuestInfoStructuredInfoIsEqual(const HostinfoStructuredHeader *info1, // IN:
- const HostinfoStructuredHeader *info2) // IN:
+GuestInfoDetailedDataIsEqual(const HostinfoDetailedDataHeader *info1, // IN:
+ const HostinfoDetailedDataHeader *info2) // IN:
{
ASSERT(info1 != NULL);
ASSERT(info2 != NULL);
/*
******************************************************************************
- * GuestInfoFreeStructuredInfo --
+ * GuestInfoFreeDetailedData --
*
* Free the HostinfoStructuredHeader and space allocated for the structured
* string.
*/
static void
-GuestInfoFreeStructuredInfo(HostinfoStructuredHeader *info) // IN/OUT:
+GuestInfoFreeDetailedData(HostinfoDetailedDataHeader *info) // IN/OUT:
{
free(info);
}
Bool sendOsNames = FALSE;
char *osName = NULL;
char *osFullName = NULL;
- char *structuredString = NULL;
+ char *detailedGosData = NULL;
/* Gather all the relevant guest information. */
osFullName = Hostinfo_GetOSName();
osName = Hostinfo_GetOSGuestString();
- if (gSendStructuredOsInfo) {
- structuredString = Hostinfo_GetOSStructuredString();
+ if (gSendDetailedGosData) {
+ detailedGosData = Hostinfo_GetOSDetailedData();
}
- if (structuredString == NULL) {
+
+ if (detailedGosData == NULL) {
g_message("No structured data.\n");
sendOsNames = TRUE;
- gSendStructuredOsInfo = FALSE;
+ gSendDetailedGosData = FALSE;
} else {
/* Build and attempt to send the structured data */
- HostinfoStructuredHeader *structuredInfoHeader = NULL;
+ HostinfoDetailedDataHeader *detailedDataHeader = NULL;
size_t infoHeaderSize;
- size_t structuredStringLen;
+ size_t detailedGosDataLen;
size_t infoSize;
g_message("Sending structured OS info.\n");
- structuredStringLen = strlen(structuredString);
- infoHeaderSize = sizeof *structuredInfoHeader;
- infoSize = infoHeaderSize + structuredStringLen + 1; // add 1 for '\0'
- structuredInfoHeader = g_malloc(infoSize);
+ detailedGosDataLen = strlen(detailedGosData);
+ infoHeaderSize = sizeof *detailedDataHeader;
+ infoSize = infoHeaderSize + detailedGosDataLen + 1; // cover NUL
+
+ detailedDataHeader = g_malloc(infoSize);
/* Clear struct and memory allocated for structured string */
- memset(structuredInfoHeader, 0, infoSize);
+ memset(detailedDataHeader, 0, infoSize);
/* Set the version of the structured header used */
- structuredInfoHeader->version = HOSTINFO_STRUCT_HEADER_VERSION;
+ detailedDataHeader->version = HOSTINFO_STRUCT_HEADER_VERSION;
if (osName == NULL) {
g_warning("Failed to get OS name.\n");
} else {
- Str_Strcpy(structuredInfoHeader->shortName, osName,
- sizeof structuredInfoHeader->shortName);
+ Str_Strcpy(detailedDataHeader->shortName, osName,
+ sizeof detailedDataHeader->shortName);
}
if (osFullName == NULL) {
g_warning("Failed to get OS full name.\n");
} else {
- Str_Strcpy(structuredInfoHeader->fullName, osFullName,
- sizeof structuredInfoHeader->fullName);
+ Str_Strcpy(detailedDataHeader->fullName, osFullName,
+ sizeof detailedDataHeader->fullName);
}
- Str_Strcpy((char *)structuredInfoHeader + infoHeaderSize,
- structuredString, infoSize - infoHeaderSize);
+ Str_Strcpy((char *)detailedDataHeader + infoHeaderSize,
+ detailedGosData, infoSize - infoHeaderSize);
- if (GuestInfoUpdateVMX(ctx, INFO_OS_STRUCTURED, structuredInfoHeader,
+ if (GuestInfoUpdateVMX(ctx, INFO_OS_DETAILED, detailedDataHeader,
infoSize)) {
- GuestInfoFreeStructuredInfo(gInfoCache.structuredOSInfo);
- gInfoCache.structuredOSInfo = structuredInfoHeader;
- g_debug("Structured OS info sent successfully.\n");
+ GuestInfoFreeDetailedData(gInfoCache.detailedData);
+ gInfoCache.detailedData = detailedDataHeader;
+ g_debug("Detailed data was sent successfully.\n");
} else {
/* Only send the OS Name if the VMX failed to receive the
* structured OS info. */
- gSendStructuredOsInfo = FALSE;
+ gSendDetailedGosData = FALSE;
sendOsNames = TRUE;
- g_debug("Structured OS info was not sent successfully.\n");
+ g_debug("Detailed data was not sent successfully.\n");
}
}
}
}
- free(structuredString);
+ free(detailedGosData);
free(osFullName);
free(osName);
} else {
gInfoCache.value[infoType] = Util_SafeStrdup((char *) info);
break;
- case INFO_OS_STRUCTURED:
+ case INFO_OS_DETAILED:
{
- if (gInfoCache.structuredOSInfo != NULL &&
- GuestInfoStructuredInfoIsEqual(gInfoCache.structuredOSInfo,
- (HostinfoStructuredHeader *)info)) {
+ if (gInfoCache.detailedData != NULL &&
+ GuestInfoDetailedDataIsEqual(gInfoCache.detailedData,
+ (HostinfoDetailedDataHeader *)info)) {
/* The value has not changed */
- g_debug("Value unchanged for structuredOSInfo.\n");
+ g_debug("Value unchanged for detailedData.\n");
break;
}
- if (!GuestInfoSendData(ctx, info, infoSize, INFO_OS_STRUCTURED)) {
+ if (!GuestInfoSendData(ctx, info, infoSize, INFO_OS_DETAILED)) {
g_warning("Failed to update structured OS information.\n");
return FALSE;
}
gInfoCache.value[i] = NULL;
}
- GuestInfoFreeStructuredInfo(gInfoCache.structuredOSInfo);
- gInfoCache.structuredOSInfo = NULL;
+ GuestInfoFreeDetailedData(gInfoCache.detailedData);
+ gInfoCache.detailedData = NULL;
GuestInfo_FreeDiskInfo(gInfoCache.diskInfo);
gInfoCache.diskInfo = NULL;
/* Reset the last gather time */
gGuestInfoLastGatherTime = 0;
- /* Reset structure guest OS data sending */
- gSendStructuredOsInfo = TRUE;
+ /* Reset detailed guest OS data sending */
+ gSendDetailedGosData = TRUE;
}