diff options
Diffstat (limited to 'hardinfo2')
| -rw-r--r-- | hardinfo2/arch/linux/common/dmi.h | 158 | ||||
| -rw-r--r-- | hardinfo2/arch/linux/common/sensors.h | 1 | ||||
| l--------- | hardinfo2/arch/linux/x86/dmi.h | 1 | ||||
| -rw-r--r-- | hardinfo2/callbacks.c | 3 | ||||
| -rw-r--r-- | hardinfo2/devices.c | 32 | ||||
| -rw-r--r-- | hardinfo2/shell.c | 4 | 
6 files changed, 197 insertions, 2 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 diff --git a/hardinfo2/callbacks.c b/hardinfo2/callbacks.c index 32db0791..521a8f18 100644 --- a/hardinfo2/callbacks.c +++ b/hardinfo2/callbacks.c @@ -204,6 +204,7 @@ void cb_about()  	"Raytracing benchmark by John Walker (see fbench.c for details)",  	"Some code partly based on x86cpucaps by Osamu Kayasono",  	"Vendor list based on GtkSysInfo by Pissens Sebastien", +	"DMI support based on code by Stewart Adam",  	NULL      };      const gchar *artists[] = { @@ -216,7 +217,7 @@ void cb_about()      gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), "HardInfo");      gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), VERSION);      gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), -				   "Copyright \302\251 2003-2007 " +				   "Copyright \302\251 2003-2008 "  				   "Leandro A. F. Pereira");      gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about),  				  "System information and benchmark tool"); diff --git a/hardinfo2/devices.c b/hardinfo2/devices.c index 6221769c..1d3c73db 100644 --- a/hardinfo2/devices.c +++ b/hardinfo2/devices.c @@ -36,6 +36,9 @@ enum {      DEVICES_PRINTERS,      DEVICES_BATTERY,      DEVICES_SENSORS, +#if defined(ARCH_i386) || defined(ARCH_x86_64) +    DEVICES_DMI, +#endif      DEVICES_INPUT,      DEVICES_STORAGE,  } Entries; @@ -49,6 +52,9 @@ gchar *callback_printers();  gchar *callback_storage();  gchar *callback_input();  gchar *callback_usb(); +#if defined(ARCH_i386) || defined(ARCH_x86_64) +gchar *callback_dmi(); +#endif  void scan_processors(gboolean reload);  void scan_memory(gboolean reload); @@ -59,6 +65,9 @@ void scan_printers(gboolean reload);  void scan_storage(gboolean reload);  void scan_input(gboolean reload);  void scan_usb(gboolean reload); +#if defined(ARCH_i386) || defined(ARCH_x86_64) +void scan_dmi(gboolean reload); +#endif  static ModuleEntry entries[] = {      {"Processor", "processor.png", callback_processors, scan_processors}, @@ -68,6 +77,9 @@ static ModuleEntry entries[] = {      {"Printers", "printer.png", callback_printers, scan_printers,},      {"Battery", "battery.png", callback_battery, scan_battery},      {"Sensors", "therm.png", callback_sensors, scan_sensors}, +#if defined(ARCH_i386) || defined(ARCH_x86_64) +    {"DMI", "computer.png", callback_dmi, scan_dmi}, +#endif	/* x86 or x86_64 */      {"Input Devices", "inputdevices.png", callback_input, scan_input},      {"Storage", "hdd.png", callback_storage, scan_storage},      {NULL} @@ -124,6 +136,10 @@ typedef struct _Processor Processor;  #include <arch/this/sensors.h>  #include <arch/this/devmemory.h> +#if defined(ARCH_i386) || defined(ARCH_x86_64) +#include <arch/this/dmi.h> +#endif	/* x86 or x86_64 */ +  gchar *get_processor_name(void)  {      scan_processors(FALSE); @@ -193,6 +209,15 @@ gchar *hi_get_field(gchar * field)      return g_strdup(field);  } +#if defined(ARCH_i386) || defined(ARCH_x86_64) +void scan_dmi(gboolean reload) +{ +    SCAN_START(); +    __scan_dmi(); +    SCAN_END(); +} +#endif +  void scan_processors(gboolean reload)  {      SCAN_START(); @@ -266,6 +291,13 @@ gchar *callback_processors()      return processor_get_info(processors);  } +#if defined(ARCH_i386) || defined(ARCH_x86_64) +gchar *callback_dmi() +{ +    return dmi_info; +} +#endif +  gchar *callback_memory()  {      return g_strdup_printf("[Memory]\n" diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c index ca246704..34a2340e 100644 --- a/hardinfo2/shell.c +++ b/hardinfo2/shell.c @@ -485,6 +485,10 @@ static void add_modules_to_gui(gpointer data, gpointer user_data)      ShellModule *module = (ShellModule *) data;      GtkTreeStore *store = GTK_TREE_STORE(shelltree->model);      GtkTreeIter parent; +     +    if (!module) { +        return; +    }      gtk_tree_store_append(store, &parent, NULL);      gtk_tree_store_set(store, &parent, TREE_COL_NAME, module->name, | 
