Changeset 5286

Show
Ignore:
Timestamp:
06/19/08 10:38:44 (5 years ago)
Author:
khali
Message:

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.

Location:
lm-sensors/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r5285 r5286  
    44SVN-HEAD 
    55  Library: Don't choke on unrecognized devices, part 2 
     6           Parse the configuration file in C locale (#2312) 
    67  Module asb100: Remove some dead code (2.6 backport) 
    78  Module i2c-amd756: Fix functionality flags (2.6 backport) 
  • lm-sensors/trunk/lib/init.c

    r4790 r5286  
    1818*/ 
    1919 
     20#include <locale.h> 
    2021#include <stdlib.h> 
    2122#include <stdio.h> 
     23#include <string.h> 
    2224#include "sensors.h" 
    2325#include "data.h" 
     
    3941static void free_ignore(sensors_ignore ignore); 
    4042 
     43/* Wrapper around sensors_yyparse(), which clears the locale so that 
     44   the decimal numbers are always parsed properly. */ 
     45static int sensors_parse(void) 
     46{ 
     47  int res; 
     48  char *locale; 
     49 
     50  /* Remember the current locale and clear it */ 
     51  locale = setlocale(LC_ALL, NULL); 
     52  if (locale) { 
     53    locale = strdup(locale); 
     54    setlocale(LC_ALL, "C"); 
     55  } 
     56 
     57  res = sensors_yyparse(); 
     58 
     59  /* Restore the old locale */ 
     60  if (locale) { 
     61    setlocale(LC_ALL, locale); 
     62    free(locale); 
     63  } 
     64 
     65  return res; 
     66} 
     67 
    4168int sensors_init(FILE *input) 
    4269{ 
     
    5279  if ((res = sensors_scanner_init(input))) 
    5380    return -SENSORS_ERR_PARSE; 
    54   if ((res = sensors_yyparse())) 
     81  if ((res = sensors_parse())) 
    5582    return -SENSORS_ERR_PARSE; 
    5683  if ((res = sensors_substitute_busses()))