From 3e46333e7c72cc655f86860c575d0b3179d846f2 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sat, 24 Nov 2007 10:46:02 +0000 Subject: [PATCH] Fix sysfs presence detection. Since sysfsutils 2.0.0, libsysfs will return success even if sysfs isn't mounted. We have to check by ourselves if it is mounted or not, so that we can fallback to procfs on Linux 2.4 systems. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5036 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + lib/sysfs.c | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index c3fb6370..862c1016 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ lm_sensors CHANGES file SVN-HEAD Library: Fix fschrc and fschmd support + Fix sysfs presence detection Makefile: Revert changeset 4738, fix bug #2187 differently Module eeprom: Hide Sony Vaio serial numbers to regular users (2.6 backport) Drop useless debugging log messages diff --git a/lib/sysfs.c b/lib/sysfs.c index 26c0ac05..8e162376 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -20,6 +20,9 @@ /* this define needed for strndup() */ #define _GNU_SOURCE +#include +#include +#include #include #include #include @@ -38,7 +41,13 @@ char sensors_sysfs_mount[NAME_MAX]; /* returns !0 if sysfs filesystem was found, 0 otherwise */ int sensors_init_sysfs(void) { - if (sysfs_get_mnt_path(sensors_sysfs_mount, NAME_MAX) == 0) + struct stat statbuf; + + /* libsysfs will return success even if sysfs is not mounted, + so we have to double-check */ + if (sysfs_get_mnt_path(sensors_sysfs_mount, NAME_MAX) == 0 + && stat(sensors_sysfs_mount, &statbuf) == 0 + && statbuf.st_nlink > 2) sensors_found_sysfs = 1; return sensors_found_sysfs;