Index: lm-sensors/trunk/lib/conf-lex.l
===================================================================
--- lm-sensors/trunk/lib/conf-lex.l	(revision 3296)
+++ lm-sensors/trunk/lib/conf-lex.l	(revision 3300)
@@ -26,4 +26,5 @@
 #include "conf-parse.h"
 #include "error.h"
+#include "scanner.h"
 
 static int buffer_count;
@@ -49,4 +50,5 @@
 
 %option nodefault
+%option noyywrap
 %option yylineno
 %option nounput
@@ -270,8 +272,29 @@
 %%
 
-int sensors_yywrap(void)
+/*
+	Do the buffer handling manually.  This allows us to scan as many
+	config files as we need to, while cleaning up properly after each
+	one.  The "BEGIN(0)" line ensures that we start in the default state,
+	even if e.g. the previous config file was syntactically broken.
+
+	Returns 0 if successful, !0 otherwise.
+*/
+
+static YY_BUFFER_STATE scan_buf = (YY_BUFFER_STATE)0;
+
+int sensors_scanner_init(FILE *input)
 {
-  yy_delete_buffer(YY_CURRENT_BUFFER);
-  return 1;
+	BEGIN(0);
+	if (!(scan_buf = sensors_yy_create_buffer(input, YY_BUF_SIZE)))
+		return -1;
+
+	sensors_yy_switch_to_buffer(scan_buf);
+	return 0;
 }
 
+void sensors_scanner_exit(void)
+{
+	sensors_yy_delete_buffer(scan_buf);
+	scan_buf = (YY_BUFFER_STATE)0;
+}
+
