aboutsummaryrefslogtreecommitdiff
path: root/hardinfo2/arch/linux
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2008-05-18 14:26:36 +0000
committerLeandro A. F. Pereira <leandro@hardinfo.org>2008-05-18 14:26:36 +0000
commitcb4e0ce108d4da27400abfeca1d5d6d3de373d0b (patch)
tree4798699fc00a5ff3aa83e2c22cbb400681abfd58 /hardinfo2/arch/linux
parent6e3c288210c382b93e8c0e6243d7d81b6dffd7ce (diff)
Add DMI support for x86 and x86-64 architectures. Support is based on patch by Stewart Adam (berlios patch #2272).
Diffstat (limited to 'hardinfo2/arch/linux')
-rw-r--r--hardinfo2/arch/linux/common/dmi.h158
-rw-r--r--hardinfo2/arch/linux/common/sensors.h1
l---------hardinfo2/arch/linux/x86/dmi.h1
3 files changed, 159 insertions, 1 deletions
diff --git a/hardinfo2/arch/linux/common/dmi.h b/hardinfo2/arch/linux/common/dmi.h
new file mode 100644
index 00000000..14534955
--- /dev/null
+++ b/hardinfo2/arch/linux/common/dmi.h
@@ -0,0 +1,158 @@
+/*
+ * HardInfo - Displays System Information
+ * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@linuxmag.com.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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+/*
+ * DMI support based on patch by Stewart Adam <s.adam@diffingo.com>
+ */
+#include <unistd.h>
+#include <sys/types.h>
+
+typedef struct _DMIInfo DMIInfo;
+
+struct _DMIInfo {
+ const gchar *name;
+ const gchar *file; /* for sysfs */
+ const gchar *param; /* for dmidecode */
+};
+
+DMIInfo dmi_info_table[] = {
+ { "$BIOS", NULL },
+ { "Date", "/sys/class/dmi/id/bios_date", "bios-release-date" },
+ { "Vendor", "/sys/class/dmi/id/bios_vendor", "bios-vendor" },
+ { "Version", "/sys/class/dmi/id/bios_version", "bios-version" },
+ { "$Board", NULL },
+ { "Name", "/sys/class/dmi/id/board_name", "baseboard-product-name" },
+ { "Vendor", "/sys/class/dmi/id/board_vendor", "baseboard-manufacturer" },
+};
+
+static gchar *dmi_info = NULL;
+
+gboolean dmi_get_info_dmidecode()
+{
+ FILE *dmi_pipe;
+ gchar buffer[256];
+ DMIInfo *info;
+ gboolean dmi_failed = FALSE;
+ gint i;
+
+ 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->name) == '$') {
+ dmi_info = h_strdup_cprintf("[%s]\n", dmi_info,
+ (info->name) + 1);
+ } else {
+ gchar *temp;
+
+ if (!info->param)
+ continue;
+
+ temp = g_strconcat("dmidecode -s ", info->param, NULL);
+
+ if ((dmi_pipe = popen(temp, "r"))) {
+ g_free(temp);
+
+ fgets(buffer, 256, dmi_pipe);
+ if (pclose(dmi_pipe)) {
+ dmi_failed = TRUE;
+ break;
+ }
+
+ dmi_info = h_strdup_cprintf("%s=%s\n",
+ dmi_info,
+ info->name,
+ buffer);
+ } else {
+ dmi_failed = TRUE;
+ }
+ }
+ }
+
+ if (dmi_failed) {
+ g_free(dmi_info);
+ dmi_info = NULL;
+ }
+
+ return !dmi_failed;
+}
+
+gboolean dmi_get_info_sys()
+{
+ FILE *dmi_file;
+ gchar buffer[256];
+ DMIInfo *info;
+ gboolean dmi_failed = FALSE;
+ gint i;
+
+ 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->name) == '$') {
+ dmi_info = h_strdup_cprintf("[%s]\n", dmi_info,
+ (info->name) + 1);
+ } else {
+ if (!info->file)
+ continue;
+
+ if ((dmi_file = fopen(info->file, "r"))) {
+ fgets(buffer, 256, dmi_file);
+ fclose(dmi_file);
+
+ dmi_info = h_strdup_cprintf("%s=%s\n",
+ dmi_info,
+ info->name,
+ buffer);
+ } else {
+ dmi_failed = TRUE;
+ }
+ }
+ }
+
+ if (dmi_failed) {
+ g_free(dmi_info);
+ dmi_info = NULL;
+ }
+
+ return !dmi_failed;
+}
+
+void __scan_dmi()
+{
+ gboolean dmi_ok;
+
+ dmi_ok = dmi_get_info_sys();
+
+ if (!dmi_ok) {
+ dmi_ok = dmi_get_info_dmidecode();
+ }
+
+ 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");
+ }
+}
diff --git a/hardinfo2/arch/linux/common/sensors.h b/hardinfo2/arch/linux/common/sensors.h
index 317d2ebb..cc370560 100644
--- a/hardinfo2/arch/linux/common/sensors.h
+++ b/hardinfo2/arch/linux/common/sensors.h
@@ -39,7 +39,6 @@ static void read_sensor_labels(gchar * driver)
if (!conf) {
/* Cannot open config file. */
- fprintf(stderr, "Cannot open /etc/sensors.conf file.\n");
return;
}
diff --git a/hardinfo2/arch/linux/x86/dmi.h b/hardinfo2/arch/linux/x86/dmi.h
new file mode 120000
index 00000000..1a285fbd
--- /dev/null
+++ b/hardinfo2/arch/linux/x86/dmi.h
@@ -0,0 +1 @@
+../../../arch/linux/common/dmi.h \ No newline at end of file