diff options
author | Burt P <pburt0@gmail.com> | 2017-08-15 17:25:44 -0500 |
---|---|---|
committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2017-08-27 08:21:05 -0700 |
commit | aceb905d3750a438e9c6c08c65f97eda2166c56a (patch) | |
tree | b2f67efce8f5900892e109ff64da6c844fc4ca1a | |
parent | 6fe6030a0b1d4534c2983b9bddee48f23af8e9af (diff) |
DMI: add dmi_sysfs_root() to find path for dmi in sysfs
Signed-off-by: Burt P <pburt0@gmail.com>
-rw-r--r-- | modules/devices/dmi.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/modules/devices/dmi.c b/modules/devices/dmi.c index 3eefd811..b89f5acc 100644 --- a/modules/devices/dmi.c +++ b/modules/devices/dmi.c @@ -47,6 +47,21 @@ DMIInfo dmi_info_table[] = { gchar *dmi_info = NULL; +const char *dmi_sysfs_root() { + char *candidates[] = { + "/sys/devices/virtual/dmi", + "/sys/class/dmi", + NULL + }; + int i = 0; + while (candidates[i] != NULL) { + if(access(candidates[i], F_OK) != -1) + return candidates[i]; + i++; + } + return NULL; +} + char *dmi_get_str(const char *id_str) { static struct { char *id; @@ -64,6 +79,7 @@ char *dmi_get_str(const char *id_str) { { "chassis-type", "id/chassis_type" }, { NULL, NULL } }; + const gchar *dmi_root = dmi_sysfs_root(); gchar *path = NULL, *full_path = NULL, *ret = NULL; gboolean spawned; gchar *out, *err; @@ -78,8 +94,8 @@ char *dmi_get_str(const char *id_str) { } /* try sysfs first */ - if (path) { - full_path = g_strdup_printf("/sys/class/dmi/%s", path); + if (dmi_root && path) { + full_path = g_strdup_printf("%s/%s", dmi_root, path); if (g_file_get_contents(full_path, &ret, NULL, NULL) ) goto dmi_str_done; } |