aboutsummaryrefslogtreecommitdiff
path: root/modules/devices/dmi.c
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2024-04-22 00:35:53 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2024-04-22 00:35:53 -0300
commit5f01c706267c595de92406a32e7f31ef5056c2d0 (patch)
treed1e74ef54efc41ada622900fe3e2a50dee44a237 /modules/devices/dmi.c
parent09fcc751ef158898c315ebc9299a0fa3a722d914 (diff)
New upstream version 2.0.3preupstream/2.0.3pre
Diffstat (limited to 'modules/devices/dmi.c')
-rw-r--r--modules/devices/dmi.c156
1 files changed, 92 insertions, 64 deletions
diff --git a/modules/devices/dmi.c b/modules/devices/dmi.c
index b25cfe21..34374fbe 100644
--- a/modules/devices/dmi.c
+++ b/modules/devices/dmi.c
@@ -1,10 +1,10 @@
/*
* HardInfo - Displays System Information
- * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org>
+ * Copyright (C) 2003-2007 L. A. F. Pereira <l@tia.mat.br>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, version 2.
+ * the Free Software Foundation, version 2 or later.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -30,26 +30,29 @@ struct _DMIInfo {
const gchar *name;
const gchar *id_str;
int group;
+ gboolean maybe_vendor;
};
DMIInfo dmi_info_table[] = {
{ N_("Product"), NULL, 1 },
{ N_("Name"), "system-product-name", 0 },
{ N_("Family"), "system-product-family", 0 },
- { N_("Vendor"), "system-manufacturer", 0 },
+ { N_("Vendor"), "system-manufacturer", 0, TRUE },
{ N_("Version"), "system-version", 0 },
+ { N_("Serial Number"), "system-serial-number", 0 },
+ { N_("SKU"), "system-sku", 0 },
{ N_("BIOS"), NULL, 1 },
{ N_("Date"), "bios-release-date", 0 },
- { N_("Vendor"), "bios-vendor", 0 },
+ { N_("Vendor"), "bios-vendor", 0, TRUE },
{ N_("Version"), "bios-version", 0 },
{ N_("Board"), NULL, 1 },
{ N_("Name"), "baseboard-product-name", 0 },
- { N_("Vendor"), "baseboard-manufacturer", 0 },
+ { N_("Vendor"), "baseboard-manufacturer", 0, TRUE },
{ N_("Version"), "baseboard-version", 0 },
{ N_("Serial Number"), "baseboard-serial-number", 0 },
{ N_("Asset Tag"), "baseboard-asset-tag", 0 },
{ N_("Chassis"), NULL, 1 },
- { N_("Vendor"), "chassis-manufacturer", 0 },
+ { N_("Vendor"), "chassis-manufacturer", 0, TRUE },
{ N_("Type"), "chassis-type", 0 },
{ N_("Version"), "chassis-version", 0 },
{ N_("Serial Number"), "chassis-serial-number", 0 },
@@ -64,77 +67,102 @@ static void add_to_moreinfo(const char *group, const char *key, char *value)
moreinfo_add_with_prefix("DEV", new_key, g_strdup(g_strstrip(value)));
}
-gboolean dmi_get_info()
+gboolean dmi_get_info(void)
{
- const gchar *group = NULL;
- DMIInfo *info;
- gboolean dmi_succeeded = FALSE;
- gint i;
- gchar *value;
-
- if (dmi_info) {
- g_free(dmi_info);
- dmi_info = NULL;
- }
+ const gchar *group = NULL;
+ DMIInfo *info;
+ gboolean dmi_succeeded = FALSE;
+ guint i;
+ gchar *value;
+ const gchar *vendor;
+
+ if (dmi_info) {
+ g_free(dmi_info);
+ dmi_info = NULL;
+ }
- for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) {
- info = &dmi_info_table[i];
-
- if (info->group) {
- group = info->name;
- dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, _(info->name) );
- } else if (group && info->id_str) {
- if (strcmp(info->id_str, "chassis-type") == 0)
- value = dmi_chassis_type_str(-1, 1);
- else
- value = dmi_get_str(info->id_str);
-
- if (value != NULL) {
- add_to_moreinfo(group, info->name, value);
-
- const gchar *url = vendor_get_url(value);
- if (url) {
- const gchar *vendor = vendor_get_name(value);
- dmi_info = h_strdup_cprintf("%s=%s (%s, %s)\n",
- dmi_info,
- _(info->name),
- value,
- vendor, url);
- } else {
- dmi_info = h_strdup_cprintf("%s=%s\n",
- dmi_info,
- _(info->name),
- value);
+ for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) {
+ info = &dmi_info_table[i];
+
+ if (info->group) {
+ group = info->name;
+ dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, _(info->name));
+ } else if (group && info->id_str) {
+ int state = 3;
+
+ if (strcmp(info->id_str, "chassis-type") == 0) {
+ value = dmi_chassis_type_str(-1, 1);
+ if (value == NULL)
+ state = (getuid() == 0) ? 0 : 1;
+ }
+ else {
+ switch (dmi_str_status(info->id_str)) {
+ case 0:
+ value = NULL;
+ state = (getuid() == 0) ? 0 : 1;
+ break;
+ case -1:
+ state = 2;
+ value = dmi_get_str_abs(info->id_str);
+ break;
+ case 1:
+ value = dmi_get_str_abs(info->id_str);
+ break;
+ }
+ }
+
+ switch (state) {
+ case 0: /* no value, root */
+ dmi_info = h_strdup_cprintf("%s=%s\n", dmi_info, _(info->name),
+ _("(Not available)"));
+ break;
+ case 1: /* no value, no root */
+ dmi_info = h_strdup_cprintf("%s=%s\n", dmi_info, _(info->name),
+ _("(Not available; Perhaps try "
+ "running HardInfo as root.)"));
+ break;
+ case 2: /* ignored value */
+ if (params.markup_ok)
+ dmi_info = h_strdup_cprintf("%s=<s>%s</s>\n", dmi_info,
+ _(info->name), value);
+ else
+ dmi_info = h_strdup_cprintf("%s=[X]\"%s\"\n", dmi_info,
+ _(info->name), value);
+ break;
+ case 3: /* good value */
+ {
+ dmi_info =
+ h_strdup_cprintf("%s%s=%s\n", dmi_info,
+ info->maybe_vendor ? "$^$" : "",
+ _(info->name), value);
+ add_to_moreinfo(group, info->name, value);
+ dmi_succeeded = TRUE;
+ break;
+ }
+ }
}
- dmi_succeeded = TRUE;
- } else {
- dmi_info = h_strdup_cprintf("%s=%s\n",
- dmi_info,
- _(info->name),
- (getuid() == 0)
- ? _("(Not available)")
- : _("(Not available; Perhaps try running HardInfo as root.)") );
- }
}
- }
- if (!dmi_succeeded) {
- g_free(dmi_info);
- dmi_info = NULL;
- }
+ if (!dmi_succeeded) {
+ g_free(dmi_info);
+ dmi_info = NULL;
+ }
- return dmi_succeeded;
+ return dmi_succeeded;
}
-void __scan_dmi()
+void __scan_dmi(void)
{
gboolean dmi_ok;
dmi_ok = dmi_get_info();
if (!dmi_ok) {
- dmi_info = g_strdup("[No DMI information]\n"
- "There was an error retrieving the information.=\n"
- "Please try running HardInfo as root.=\n");
+ dmi_info = g_strdup_printf("[%s]\n%s=\n",
+ _("DMI Unavailable"),
+ (getuid() == 0)
+ ? _("DMI is not avaliable. Perhaps this platform does not provide DMI.")
+ : _("DMI is not available; Perhaps try running HardInfo as root.") );
+
}
}