From a05eab4627ad24e67566cd34d6f70990dad350b5 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Mon, 8 Feb 2010 15:07:27 +0100
Subject: [PATCH] Initialize libsensors with NULL to make it use /etc/sensors3.conf *and* /etc/sensors.d/*

---
 src/sensors.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/sensors.c b/src/sensors.c
index 8391346..a50cbac 100644
--- a/src/sensors.c
+++ b/src/sensors.c
@@ -148,6 +148,10 @@ typedef struct featurelist
 # ifndef SENSORS_CONF_PATH
 #  define SENSORS_CONF_PATH "/etc/sensors.conf"
 # endif
+
+static const char *conffile = SENSORS_CONF_PATH;
+static time_t sensors_config_mtime = 0;
+
 /* #endif SENSORS_API_VERSION < 0x400 */
 
 #elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
@@ -159,9 +163,8 @@ typedef struct featurelist
 	struct featurelist         *next;
 } featurelist_t;
 
-# ifndef SENSORS_CONF_PATH
-#  define SENSORS_CONF_PATH "/etc/sensors3.conf"
-# endif
+bool initialized = false;
+
 /* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
 
 #else /* if SENSORS_API_VERSION >= 0x500 */
@@ -169,10 +172,8 @@ typedef struct featurelist
 	"as bug."
 #endif
 
-static const char *conffile = SENSORS_CONF_PATH;
 featurelist_t *first_feature = NULL;
 static ignorelist_t *sensor_list;
-static time_t sensors_config_mtime = 0;
 
 #if SENSORS_API_VERSION < 0x400
 /* full chip name logic borrowed from lm_sensors */
@@ -268,15 +269,16 @@ void sensors_free_features (void)
 
 static int sensors_load_conf (void)
 {
-	FILE *fh;
 	featurelist_t *last_feature = NULL;
 	
 	const sensors_chip_name *chip;
 	int chip_num;
 
+#if SENSORS_API_VERSION < 0x400
+	FILE *fh;
 	struct stat statbuf;
 	int status;
-	
+
 	status = stat (conffile, &statbuf);
 	if (status != 0)
 	{
@@ -317,6 +319,13 @@ static int sensors_load_conf (void)
 	}
 
 	sensors_config_mtime = statbuf.st_mtime;
+#else
+	if (initialized)
+		return (0);
+
+	sensors_init(NULL);
+	initialized = true;
+#endif
 
 #if SENSORS_API_VERSION < 0x400
 	chip_num = 0;
-- 
1.6.5

