From 253dc9c9d9e9d933c9bc80eb6ba8cc309a180a5a Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 19 Jun 2008 08:38:44 +0000 Subject: [PATCH] The configuration file is currently parsed in the locale set by the main program using the library. This means that if the decimal separator (defined in LC_NUMERIC) is not '.' the values in the compute lines are truncated. This happens for example with sensors-applet and a French locale. http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=469333 Parsing the configuration file in C locale fixes the problem. Original patch from Aurelien Jarno. Also closes ticket #2312. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5286 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + lib/init.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 04bdbe93..abdbed9d 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ lm_sensors CHANGES file SVN-HEAD Library: Don't choke on unrecognized devices, part 2 + Parse the configuration file in C locale (#2312) Module asb100: Remove some dead code (2.6 backport) Module i2c-amd756: Fix functionality flags (2.6 backport) Module i2c-amd756-s4882: Fix an error path (2.6 backport) diff --git a/lib/init.c b/lib/init.c index c7d9734c..2e7f696c 100644 --- a/lib/init.c +++ b/lib/init.c @@ -17,8 +17,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include +#include #include "sensors.h" #include "data.h" #include "proc.h" @@ -38,6 +40,31 @@ static void free_set(sensors_set set); static void free_compute(sensors_compute compute); static void free_ignore(sensors_ignore ignore); +/* Wrapper around sensors_yyparse(), which clears the locale so that + the decimal numbers are always parsed properly. */ +static int sensors_parse(void) +{ + int res; + char *locale; + + /* Remember the current locale and clear it */ + locale = setlocale(LC_ALL, NULL); + if (locale) { + locale = strdup(locale); + setlocale(LC_ALL, "C"); + } + + res = sensors_yyparse(); + + /* Restore the old locale */ + if (locale) { + setlocale(LC_ALL, locale); + free(locale); + } + + return res; +} + int sensors_init(FILE *input) { int res; @@ -51,7 +78,7 @@ int sensors_init(FILE *input) } if ((res = sensors_scanner_init(input))) return -SENSORS_ERR_PARSE; - if ((res = sensors_yyparse())) + if ((res = sensors_parse())) return -SENSORS_ERR_PARSE; if ((res = sensors_substitute_busses())) return res;