Merge branch 'collectd-5.4' into collectd-5.5
[collectd.git] / src / daemon / collectd.c
index a708665..6e625bb 100644 (file)
@@ -197,8 +197,10 @@ static int change_basedir (const char *orig_dir)
        while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
                dir[--dirlen] = '\0';
 
-       if (dirlen <= 0)
+       if (dirlen <= 0) {
+               free (dir);
                return (-1);
+       }
 
        status = chdir (dir);
        if (status == 0)
@@ -300,6 +302,11 @@ static int do_init (void)
 #if HAVE_SETLOCALE
        if (setlocale (LC_NUMERIC, COLLECTD_LOCALE) == NULL)
                WARNING ("setlocale (\"%s\") failed.", COLLECTD_LOCALE);
+
+       /* Update the environment, so that libraries that are calling
+        * setlocale(LC_NUMERIC, "") don't accidentally revert these changes. */
+       unsetenv ("LC_ALL");
+       setenv ("LC_NUMERIC", COLLECTD_LOCALE, /* overwrite = */ 1);
 #endif
 
 #if HAVE_LIBKSTAT
@@ -408,14 +415,15 @@ static int pidfile_create (void)
 static int pidfile_remove (void)
 {
        const char *file = global_option_get ("PIDFile");
+       if (file == NULL)
+               return 0;
 
-       DEBUG ("unlink (%s)", (file != NULL) ? file : "<null>");
        return (unlink (file));
 } /* static int pidfile_remove (const char *file) */
 #endif /* COLLECT_DAEMON */
 
 #ifdef KERNEL_LINUX
-int notify_upstart (void)
+static int notify_upstart (void)
 {
     const char  *upstart_job = getenv("UPSTART_JOB");
 
@@ -432,7 +440,7 @@ int notify_upstart (void)
     return 1;
 }
 
-int notify_systemd (void)
+static int notify_systemd (void)
 {
     int                  fd = -1;
     const char          *notifysocket = getenv("NOTIFY_SOCKET");