libsensors: More reliable detection of sysfs being mounted
PATCH 1/1 libsensors: More reliable detection of sysfs being mounted
Upcoming change in sysfs will break the way libsensors detects if sysfs is mounted. Adjust the implementation so that it still works after said change.
--- lib/sysfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
lib/sysfs.c +5 -3
@@ -24,6 +24,7 @@#include <sys/types.h> #include <sys/stat.h> +#include <sys/vfs.h> #include <unistd.h> #include <string.h> #include <stdlib.h>
@@ -40,6 +41,7 @@/****************************************************************************/ #define ATTR_MAX 128 +#define SYSFS_MAGIC 0x62656572/* * Read an attribute from sysfs
@@ -593,11 +595,11 @@ exit_free:/* returns !0 if sysfs filesystem was found, 0 otherwise */ int sensors_init_sysfs (void ) { -struct stat statbuf; +struct statfs statfsbuf;snprintf (sensors_sysfs_mount,NAME_MAX ,"%s" ,"/sys" ); -if (stat (sensors_sysfs_mount, &statbuf) <0 - || statbuf.st_nlink <=2 )/* Empty directory */ +if (statfs (sensors_sysfs_mount, &statfsbuf) <0 + || statfsbuf.f_type !=SYSFS_MAGIC )return 0 ;return 1 ;
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 32 lines · Jean Delvare
Upcoming change in sysfs will break the way libsensors detects if sysfs is mounted. Adjust the implementation so that it still works after said change.
--- lib/sysfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)lib/sysfs.c +2
-1@@ -24,6 +24,7 @@#include <sys/types.h> #include <sys/stat.h> +#include <sys/vfs.h> #include <unistd.h> #include <string.h> #include <stdlib.h> @@ -40,6 +41,7 @@/****************************************************************************/ #define ATTR_MAX 128 +#define SYSFS_MAGIC 0x62656572/* * Read an attribute from sysfs @@ -593,11 +595,11 @@ exit_free:/* returns !0 if sysfs filesystem was found, 0 otherwise */ int sensors_init_sysfs (void ) { -struct stat statbuf;
lib/sysfs.c exit_free: · line 605
Quoted 10 lines
lib/sysfs.c +3
-2+struct statfs statfsbuf;snprintf (sensors_sysfs_mount,NAME_MAX ,"%s" ,"/sys" ); -if (stat (sensors_sysfs_mount, &statbuf) <0 - || statbuf.st_nlink <=2 )/* Empty directory */ +if (statfs (sensors_sysfs_mount, &statfsbuf) <0 + || statfsbuf.f_type !=SYSFS_MAGIC )return 0 ;return 1 ;
Looks good. Hope that won't bite us too much after 3.4 is released.
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors