/*
* sysinfo.c: get SMBIOS/sysinfo information from the host
*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
* Copyright (C) 2010 Daniel Veillard
*
* This library is free software; you can redistribute it and/or
#else /* !WIN32 && x86 */
-static char *
-virSysinfoParseBIOS(char *base, virSysinfoDefPtr ret)
+static int
+virSysinfoParseBIOS(const char *base, virSysinfoDefPtr ret)
{
- char *cur, *eol = NULL;
+ const char *cur, *eol = NULL;
if ((cur = strstr(base, "BIOS Information")) == NULL)
- return base;
+ return 0;
base = cur;
if ((cur = strstr(base, "Vendor: ")) != NULL) {
goto no_memory;
}
- return base + strlen("BIOS Information");
+ return 0;
no_memory:
- return NULL;
+ return -1;
}
-static char *
-virSysinfoParseSystem(char *base, virSysinfoDefPtr ret)
+static int
+virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret)
{
- char *cur, *eol = NULL;
+ const char *cur, *eol = NULL;
if ((cur = strstr(base, "System Information")) == NULL)
- return base;
+ return 0;
base = cur;
if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
goto no_memory;
}
- return base + strlen("System Information");
+ return 0;
no_memory:
- return NULL;
+ return -1;
}
-static char *
-virSysinfoParseProcessor(char *base, virSysinfoDefPtr ret)
+static int
+virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret)
{
- char *cur, *eol, *tmp_base;
+ const char *cur, *tmp_base;
+ char *eol;
virSysinfoProcessorDefPtr processor;
while((tmp_base = strstr(base, "Processor Information")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_socket_destination = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_socket_destination
+ = strndup(cur, eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Type: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_family = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_family = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Manufacturer: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_manufacturer = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_manufacturer
+ = strndup(cur, eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Signature: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_signature = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_signature
+ = strndup(cur, eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Version: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_version = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_version = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "External Clock: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_external_clock = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_external_clock
+ = strndup(cur, eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Max Speed: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_max_speed = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_max_speed
+ = strndup(cur, eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Status: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_status = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_status = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Serial Number: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_serial_number = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_serial_number
+ = strndup(cur, eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Part Number: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((processor->processor_part_number = strndup(cur, eol - cur)) == NULL))
+ ((processor->processor_part_number
+ = strndup(cur, eol - cur)) == NULL))
goto no_memory;
}
base += strlen("Processor Information");
}
- return base;
+ return 0;
no_memory:
- return NULL;
+ return -1;
}
-static char *
-virSysinfoParseMemory(char *base, virSysinfoDefPtr ret)
+static int
+virSysinfoParseMemory(const char *base, virSysinfoDefPtr ret)
{
- char *cur, *eol, *tmp_base;
+ const char *cur, *tmp_base;
+ char *eol;
virSysinfoMemoryDefPtr memory;
while ((tmp_base = strstr(base, "Memory Device")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((memory->memory_form_factor = strndup(cur, eol - cur)) == NULL))
+ ((memory->memory_form_factor = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Locator: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((memory->memory_bank_locator = strndup(cur, eol - cur)) == NULL))
+ ((memory->memory_bank_locator = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Type: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((memory->memory_type_detail = strndup(cur, eol - cur)) == NULL))
+ ((memory->memory_type_detail = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Speed: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((memory->memory_manufacturer = strndup(cur, eol - cur)) == NULL))
+ ((memory->memory_manufacturer = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Serial Number: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((memory->memory_serial_number = strndup(cur, eol - cur)) == NULL))
+ ((memory->memory_serial_number = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
if ((cur = strstr(base, "Part Number: ")) != NULL) {
eol = strchr(cur, '\n');
virSkipSpacesBackwards(cur, &eol);
if ((eol) &&
- ((memory->memory_part_number = strndup(cur, eol - cur)) == NULL))
+ ((memory->memory_part_number = strndup(cur,
+ eol - cur)) == NULL))
goto no_memory;
}
base += strlen("Memory Device");
}
- return base;
+ return 0;
no_memory:
- return NULL;
+ return -1;
}
virSysinfoDefPtr
ret->type = VIR_SYSINFO_SMBIOS;
- if ((virSysinfoParseBIOS(outbuf, ret)) == NULL)
+ if (virSysinfoParseBIOS(outbuf, ret) < 0)
goto no_memory;
- if ((virSysinfoParseSystem(outbuf, ret)) == NULL)
+ if (virSysinfoParseSystem(outbuf, ret) < 0)
goto no_memory;
ret->nprocessor = 0;
ret->processor = NULL;
- if ((virSysinfoParseProcessor(outbuf, ret)) == NULL)
+ if (virSysinfoParseProcessor(outbuf, ret) < 0)
goto no_memory;
ret->nmemory = 0;
ret->memory = NULL;
- if (virSysinfoParseMemory(outbuf, ret) == NULL)
+ if (virSysinfoParseMemory(outbuf, ret) < 0)
goto no_memory;
cleanup: