From 2578c91335381de7cf1da589f8993e775483319e Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 17 Sep 2014 10:52:36 +0200 Subject: [PATCH] src/collectd.c: Set the LC_NUMERIC locale to "C". When using ASCII protocols, such as the Graphite protocol, doubles are converted to strings using sprintf(3) and parsed with strtod(3). If the effective locale uses something different from a dot (".") as the decimal separator (e.g. Portuguese, German), this breaks. This patch sets the LC_NUMERIC locale to "C" on start-up, so that strings are produced and parsed in a well-defined manner. Fixes: #512 --- configure.ac | 4 ++-- src/collectd.c | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index bcd8b602..65e535a6 100644 --- a/configure.ac +++ b/configure.ac @@ -527,7 +527,7 @@ AC_CHECK_HEADERS(linux/un.h, [], [], #endif ]) -AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h wordexp.h) +AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h kvm.h wordexp.h locale.h) # For the dns plugin AC_CHECK_HEADERS(arpa/nameser.h) @@ -602,7 +602,7 @@ AC_HEADER_TIME # Checks for library functions. # AC_PROG_GCC_TRADITIONAL -AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname) +AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale) AC_FUNC_STRERROR_R diff --git a/src/collectd.c b/src/collectd.c index f711fb70..2e2d821a 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -28,19 +28,27 @@ #include "collectd.h" #include "common.h" +#include "plugin.h" +#include "configfile.h" + #include #include #include #include -#include "plugin.h" -#include "configfile.h" +#if HAVE_LOCALE_H +# include +#endif #if HAVE_STATGRAB_H # include #endif +#ifndef COLLECTD_LOCALE +# define COLLECTD_LOCALE "C" +#endif + /* * Global variables */ @@ -288,6 +296,11 @@ static void exit_usage (int status) static int do_init (void) { +#if HAVE_SETLOCALE + if (setlocale (LC_NUMERIC, COLLECTD_LOCALE) == NULL) + WARNING ("setlocale (\"%s\") failed.", COLLECTD_LOCALE); +#endif + #if HAVE_LIBKSTAT kc = NULL; update_kstat (); -- 2.11.0