Changeset 5169

Show
Ignore:
Timestamp:
04/08/08 16:50:13 (6 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.

Location:
lm-sensors/branches/lm-sensors-3.0.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/CHANGES

    r5134 r5169  
    44SVN-HEAD 
    55  libsensors: Use __func__ instead of __FUNCTION__ 
     6              Parse the configuration file in C locale 
    67  sensors-detect: Add SMSC SCH5027D detection 
    78                  Do not access I/O ports on PPC 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/init.c

    r5163 r5169  
    2020*/ 
    2121 
     22#include <locale.h> 
    2223#include <stdlib.h> 
    2324#include <stdio.h> 
     25#include <string.h> 
    2426#include <errno.h> 
    2527#include "sensors.h" 
     
    3537#define ALT_CONFIG_FILE         ETCDIR "/sensors.conf" 
    3638 
     39/* Wrapper around sensors_yyparse(), which clears the locale so that 
     40   the decimal numbers are always parsed properly. */ 
     41static int sensors_parse(void) 
     42{ 
     43        int res; 
     44        char *locale; 
     45 
     46        /* Remember the current locale and clear it */ 
     47        locale = setlocale(LC_ALL, NULL); 
     48        if (locale) { 
     49                locale = strdup(locale); 
     50                setlocale(LC_ALL, "C"); 
     51        } 
     52 
     53        res = sensors_yyparse(); 
     54 
     55        /* Restore the old locale */ 
     56        if (locale) { 
     57                setlocale(LC_ALL, locale); 
     58                free(locale); 
     59        } 
     60 
     61        return res; 
     62} 
     63 
    3764int sensors_init(FILE *input) 
    3865{ 
     
    4875        if (input) { 
    4976                if (sensors_scanner_init(input) || 
    50                     sensors_yyparse()) 
     77                    sensors_parse()) 
    5178                        goto exit_cleanup; 
    5279        } else { 
     
    5784                if (input) { 
    5885                        if (sensors_scanner_init(input) || 
    59                             sensors_yyparse()) { 
     86                            sensors_parse()) { 
    6087                                fclose(input); 
    6188                                goto exit_cleanup;