diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-05-23 16:55:25 +0200 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-05-23 16:55:25 +0200 |
commit | 46b79c42c4235e597d3a5e9ce7329f510c3858ec (patch) | |
tree | 68cb23d5295f9548a1896e646ae640611dbeb257 /src/hardware/dmidecode.c | |
parent | 4970da30fb16723a130104192465251b87f23fbd (diff) | |
download | openlmi-providers-46b79c42c4235e597d3a5e9ce7329f510c3858ec.tar.gz openlmi-providers-46b79c42c4235e597d3a5e9ce7329f510c3858ec.tar.xz openlmi-providers-46b79c42c4235e597d3a5e9ce7329f510c3858ec.zip |
Hardware: Added Baseboard (Motherboard) Provider
New Providers:
* LMI_BaseboardProvider
* LMI_BaseboardContainerProvider
Other Changes:
* Removed useless providers_SRCS from CMakeLists.txt
* Better, human friendly chassis name if type is not avaiable
Diffstat (limited to 'src/hardware/dmidecode.c')
-rw-r--r-- | src/hardware/dmidecode.c | 155 |
1 files changed, 152 insertions, 3 deletions
diff --git a/src/hardware/dmidecode.c b/src/hardware/dmidecode.c index d27c9dc..ab3b359 100644 --- a/src/hardware/dmidecode.c +++ b/src/hardware/dmidecode.c @@ -1107,7 +1107,6 @@ void dmi_free_memory(DmiMemory *memory) * DmiChassis */ - /* * Initialize DmiChassis attributes. * @param chassis @@ -1187,6 +1186,13 @@ short dmi_get_chassis(DmiChassis *chassis) goto done; } + /* empty output from dmidecode */ + if (buffer_size < 5) { + warn("Dmidecode has no information about chassis."); + ret = -3; + goto done; + } + /* parse information about chassis */ for (i = 0; i < buffer_size; i++) { /* Serial Number */ @@ -1217,7 +1223,7 @@ short dmi_get_chassis(DmiChassis *chassis) buf = NULL; continue; } - /* SKU Number */ + /* Version */ buf = copy_string_part_after_delim(buffer[i], "Version: "); if (buf) { chassis->version = buf; @@ -1248,7 +1254,7 @@ short dmi_get_chassis(DmiChassis *chassis) /* fill in default attributes if needed */ if (check_dmi_chassis_attributes(chassis) != 0) { - ret = -3; + ret = -4; goto done; } @@ -1278,3 +1284,146 @@ void dmi_free_chassis(DmiChassis *chassis) chassis->version = NULL; } + +/****************************************************************************** + * DmiBaseboard + */ + +/* + * Initialize DmiBaseboard attributes. + * @param baseboard + */ +void init_dmi_baseboard_struct(DmiBaseboard *baseboard) +{ + baseboard->serial_number = NULL; + baseboard->manufacturer = NULL; + baseboard->product_name = NULL; + baseboard->version = NULL; +} + +/* + * Check attributes of baseboard structure and fill in defaults if needed. + * @param baseboard + * @return 0 if success, negative value otherwise + */ +short check_dmi_baseboard_attributes(DmiBaseboard *baseboard) +{ + short ret = -1; + + if (!baseboard->serial_number) { + if (!(baseboard->serial_number = strdup("Not Specified"))) { + ret = -2; + goto done; + } + } + if (!baseboard->manufacturer) { + if (!(baseboard->manufacturer = strdup(""))) { + ret = -3; + goto done; + } + } + if (!baseboard->product_name) { + if (!(baseboard->product_name = strdup(""))) { + ret = -4; + goto done; + } + } + if (!baseboard->version) { + if (!(baseboard->version = strdup(""))) { + ret = -5; + goto done; + } + } + + ret = 0; + +done: + if (ret != 0) { + warn("Failed to allocate memory."); + } + + return ret; +} + +short dmi_get_baseboard(DmiBaseboard *baseboard) +{ + short ret = -1; + unsigned i, buffer_size = 0; + char **buffer = NULL, *buf; + + init_dmi_baseboard_struct(baseboard); + + /* get dmidecode output for baseboard */ + if (run_command("dmidecode -t 2", &buffer, &buffer_size) != 0) { + ret = -2; + goto done; + } + + /* empty output from dmidecode */ + if (buffer_size < 5) { + warn("Dmidecode has no information about baseboard."); + ret = -3; + goto done; + } + + /* parse information about baseboard */ + for (i = 0; i < buffer_size; i++) { + /* Serial Number */ + buf = copy_string_part_after_delim(buffer[i], "Serial Number: "); + if (buf) { + baseboard->serial_number = buf; + buf = NULL; + continue; + } + /* Manufacturer */ + buf = copy_string_part_after_delim(buffer[i], "Manufacturer: "); + if (buf) { + baseboard->manufacturer = buf; + buf = NULL; + continue; + } + /* Product Name */ + buf = copy_string_part_after_delim(buffer[i], "Product Name: "); + if (buf) { + baseboard->product_name = buf; + buf = NULL; + continue; + } + /* Version */ + buf = copy_string_part_after_delim(buffer[i], "Version: "); + if (buf) { + baseboard->version = buf; + buf = NULL; + continue; + } + } + + /* fill in default attributes if needed */ + if (check_dmi_baseboard_attributes(baseboard) != 0) { + ret = -4; + goto done; + } + + ret = 0; + +done: + free_2d_buffer(&buffer, &buffer_size); + + if (ret != 0) { + dmi_free_baseboard(baseboard); + } + + return ret; +} + +void dmi_free_baseboard(DmiBaseboard *baseboard) +{ + free(baseboard->serial_number); + baseboard->serial_number = NULL; + free(baseboard->manufacturer); + baseboard->manufacturer = NULL; + free(baseboard->product_name); + baseboard->product_name = NULL; + free(baseboard->version); + baseboard->version = NULL; +} |