static int virSysinfoParseSystem(const char *base, virSysinfoDefPtr ret) { char *cur, *eol = NULL; const char *property; /* Return if Manufacturer field is not found */ if ((cur = strstr(base, "Manufacturer")) == NULL) return 0; base = cur; if ((cur = strstr(base, "Manufacturer")) != NULL) { cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((property = strndup(cur, eol - cur)) == NULL)) goto no_memory; virSkipSpaces(&property); ret->system_manufacturer = (char *) property; } if ((cur = strstr(base, "Type")) != NULL) { cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((property = strndup(cur, eol - cur)) == NULL)) goto no_memory; virSkipSpaces(&property); ret->system_family = (char *) property; } if ((cur = strstr(base, "Sequence Code")) != NULL) { cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((property = strndup(cur, eol - cur)) == NULL)) goto no_memory; virSkipSpaces(&property); ret->system_serial = (char *) property; } return 0; no_memory: return -1; }
static int virSysinfoParseMemory(const char *base, virSysinfoDefPtr ret) { const char *cur, *tmp_base; char *eol; virSysinfoMemoryDefPtr memory; while ((tmp_base = strstr(base, "Memory Device")) != NULL) { base = tmp_base; eol = NULL; if (VIR_EXPAND_N(ret->memory, ret->nmemory, 1) < 0) { goto no_memory; } memory = &ret->memory[ret->nmemory - 1]; if ((cur = strstr(base, "Size: ")) != NULL) { cur += 6; eol = strchr(cur, '\n'); if (STREQLEN(cur, "No Module Installed", eol - cur)) goto next; virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_size = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Form Factor: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_form_factor = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Locator: ")) != NULL) { cur += 9; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_locator = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Bank Locator: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_bank_locator = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Type: ")) != NULL) { cur += 6; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_type = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Type Detail: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_type_detail = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Speed: ")) != NULL) { cur += 7; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_speed = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Manufacturer: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_manufacturer = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Serial Number: ")) != NULL) { cur += 15; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_serial_number = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Part Number: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((memory->memory_part_number = strndup(cur, eol - cur)) == NULL)) goto no_memory; } next: base += strlen("Memory Device"); } return 0; no_memory: return -1; }
static int virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) { const char *cur, *tmp_base; char *eol; virSysinfoProcessorDefPtr processor; while ((tmp_base = strstr(base, "Processor Information")) != NULL) { base = tmp_base; eol = NULL; if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) { goto no_memory; } processor = &ret->processor[ret->nprocessor - 1]; if ((cur = strstr(base, "Socket Designation: ")) != NULL) { cur += 20; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_socket_destination = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Type: ")) != NULL) { cur += 6; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_type = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Family: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_family = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Manufacturer: ")) != NULL) { cur += 14; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_manufacturer = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Signature: ")) != NULL) { cur += 11; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_signature = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Version: ")) != NULL) { cur += 9; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_version = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "External Clock: ")) != NULL) { cur += 16; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_external_clock = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Max Speed: ")) != NULL) { cur += 11; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_max_speed = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Status: ")) != NULL) { cur += 8; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_status = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Serial Number: ")) != NULL) { cur += 15; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_serial_number = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "Part Number: ")) != NULL) { cur += 13; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((processor->processor_part_number = strndup(cur, eol - cur)) == NULL)) goto no_memory; } base += strlen("Processor Information"); } return 0; no_memory: return -1; }
static int virSysinfoParseProcessor(const char *base, virSysinfoDefPtr ret) { char *cur, *eol, *tmp_base; char *manufacturer; const char *tmp; virSysinfoProcessorDefPtr processor; if ((cur = strstr(base, "vendor_id")) != NULL) { cur = strchr(cur, ':') + 1; eol = strchr(cur, '\n'); virSkipSpacesBackwards(cur, &eol); if ((eol) && ((tmp = strndup(cur, eol - cur)) == NULL)) goto no_memory; virSkipSpaces(&tmp); manufacturer = (char *) tmp; } /* Find processor N: line and gather the processor manufacturer, version, * serial number, and family */ while ((tmp_base = strstr(base, "processor ")) != NULL) { base = tmp_base; eol = strchr(base, '\n'); cur = strchr(base, ':') + 1; if (VIR_EXPAND_N(ret->processor, ret->nprocessor, 1) < 0) { goto no_memory; } processor = &ret->processor[ret->nprocessor - 1]; /* Set the processor manufacturer */ processor->processor_manufacturer = manufacturer; if ((cur = strstr(base, "version =")) != NULL) { cur += sizeof("version ="); eol = strchr(cur, ','); if ((eol) && ((processor->processor_version = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "identification =")) != NULL) { cur += sizeof("identification ="); eol = strchr(cur, ','); if ((eol) && ((processor->processor_serial_number = strndup(cur, eol - cur)) == NULL)) goto no_memory; } if ((cur = strstr(base, "machine =")) != NULL) { cur += sizeof("machine ="); eol = strchr(cur, '\n'); if ((eol) && ((processor->processor_family = strndup(cur, eol - cur)) == NULL)) goto no_memory; } base = cur; } return 0; no_memory: return -1; }