projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'collectd-5.5'
[collectd.git]
/
src
/
daemon
/
collectd.c
diff --git
a/src/daemon/collectd.c
b/src/daemon/collectd.c
index
cffb9a5
..
ce4922d
100644
(file)
--- a/
src/daemon/collectd.c
+++ b/
src/daemon/collectd.c
@@
-32,7
+32,6
@@
#include "configfile.h"
#include <sys/types.h>
#include "configfile.h"
#include <sys/types.h>
-#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#include <sys/un.h>
#include <netdb.h>
@@
-55,7
+54,6
@@
*/
char hostname_g[DATA_MAX_NAME_LEN];
cdtime_t interval_g;
*/
char hostname_g[DATA_MAX_NAME_LEN];
cdtime_t interval_g;
-int pidfile_from_cli = 0;
int timeout_g;
#if HAVE_LIBKSTAT
kstat_ctl_t *kc;
int timeout_g;
#if HAVE_LIBKSTAT
kstat_ctl_t *kc;
@@
-197,8
+195,10
@@
static int change_basedir (const char *orig_dir)
while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
dir[--dirlen] = '\0';
while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
dir[--dirlen] = '\0';
- if (dirlen <= 0)
+ if (dirlen == 0) {
+ free (dir);
return (-1);
return (-1);
+ }
status = chdir (dir);
if (status == 0)
status = chdir (dir);
if (status == 0)
@@
-268,6
+268,7
@@
static void update_kstat (void)
/* TODO
* Remove all settings but `-f' and `-C'
*/
/* TODO
* Remove all settings but `-f' and `-C'
*/
+__attribute__((noreturn))
static void exit_usage (int status)
{
printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n"
static void exit_usage (int status)
{
printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n"
@@
-300,6
+301,11
@@
static int do_init (void)
#if HAVE_SETLOCALE
if (setlocale (LC_NUMERIC, COLLECTD_LOCALE) == NULL)
WARNING ("setlocale (\"%s\") failed.", COLLECTD_LOCALE);
#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
#endif
#if HAVE_LIBKSTAT
@@
-325,9
+331,7
@@
static int do_init (void)
}
#endif
}
#endif
- plugin_init_all ();
-
- return (0);
+ return plugin_init_all ();
} /* int do_init () */
} /* int do_init () */
@@
-381,8
+385,7
@@
static int do_loop (void)
static int do_shutdown (void)
{
static int do_shutdown (void)
{
- plugin_shutdown_all ();
- return (0);
+ return plugin_shutdown_all ();
} /* int do_shutdown */
#if COLLECT_DAEMON
} /* int do_shutdown */
#if COLLECT_DAEMON
@@
-416,7
+419,7
@@
static int pidfile_remove (void)
#endif /* COLLECT_DAEMON */
#ifdef KERNEL_LINUX
#endif /* COLLECT_DAEMON */
#ifdef KERNEL_LINUX
-int notify_upstart (void)
+
static
int notify_upstart (void)
{
char const *upstart_job = getenv("UPSTART_JOB");
{
char const *upstart_job = getenv("UPSTART_JOB");
@@
-436,7
+439,7
@@
int notify_upstart (void)
return 1;
}
return 1;
}
-int notify_systemd (void)
+
static
int notify_systemd (void)
{
int fd;
const char *notifysocket;
{
int fd;
const char *notifysocket;
@@
-458,7
+461,11
@@
int notify_systemd (void)
unsetenv ("NOTIFY_SOCKET");
unsetenv ("NOTIFY_SOCKET");
+#if defined(SOCK_CLOEXEC)
+ fd = socket (AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, /* protocol = */ 0);
+#else
fd = socket (AF_UNIX, SOCK_DGRAM, /* protocol = */ 0);
fd = socket (AF_UNIX, SOCK_DGRAM, /* protocol = */ 0);
+#endif
if (fd < 0) {
char errbuf[1024];
ERROR ("creating UNIX socket failed: %s",
if (fd < 0) {
char errbuf[1024];
ERROR ("creating UNIX socket failed: %s",
@@
-476,7
+483,6
@@
int notify_systemd (void)
}
else
{
}
else
{
-#if KERNEL_LINUX
/* Linux abstract namespace socket: specify address as "\0foo", i.e.
* start with a null byte. Since null bytes have no special meaning in
* that case, we have to set su_size correctly to cover only the bytes
/* Linux abstract namespace socket: specify address as "\0foo", i.e.
* start with a null byte. Since null bytes have no special meaning in
* that case, we have to set su_size correctly to cover only the bytes
@@
-486,11
+492,6
@@
int notify_systemd (void)
su_size = sizeof (sa_family_t) + strlen (notifysocket);
if (su_size > sizeof (su))
su_size = sizeof (su);
su_size = sizeof (sa_family_t) + strlen (notifysocket);
if (su_size > sizeof (su))
su_size = sizeof (su);
-#else
- ERROR ("Systemd socket uses Linux abstract namespace notation (\"%s\"), "
- "but I don't appear to be running on Linux.", notifysocket);
- return 0;
-#endif
}
if (sendto (fd, buffer, strlen (buffer), MSG_NOSIGNAL, (void *) &su, (socklen_t) su_size) < 0)
}
if (sendto (fd, buffer, strlen (buffer), MSG_NOSIGNAL, (void *) &su, (socklen_t) su_size) < 0)
@@
-502,6
+503,7
@@
int notify_systemd (void)
return 0;
}
return 0;
}
+ unsetenv ("NOTIFY_SOCKET");
close(fd);
return 1;
}
close(fd);
return 1;
}
@@
-513,7
+515,7
@@
int main (int argc, char **argv)
struct sigaction sig_term_action;
struct sigaction sig_usr1_action;
struct sigaction sig_pipe_action;
struct sigaction sig_term_action;
struct sigaction sig_usr1_action;
struct sigaction sig_pipe_action;
- char *configfile = CONFIGFILE;
+ c
onst c
har *configfile = CONFIGFILE;
int test_config = 0;
int test_readall = 0;
const char *basedir;
int test_config = 0;
int test_readall = 0;
const char *basedir;
@@
-548,15
+550,14
@@
int main (int argc, char **argv)
break;
case 'T':
test_readall = 1;
break;
case 'T':
test_readall = 1;
- global_option_set ("ReadThreads", "-1");
+ global_option_set ("ReadThreads", "-1"
, 1
);
#if COLLECT_DAEMON
daemonize = 0;
#endif /* COLLECT_DAEMON */
break;
#if COLLECT_DAEMON
case 'P':
#if COLLECT_DAEMON
daemonize = 0;
#endif /* COLLECT_DAEMON */
break;
#if COLLECT_DAEMON
case 'P':
- global_option_set ("PIDFile", optarg);
- pidfile_from_cli = 1;
+ global_option_set ("PIDFile", optarg, 1);
break;
case 'f':
daemonize = 0;
break;
case 'f':
daemonize = 0;
@@
-633,6
+634,8
@@
int main (int argc, char **argv)
#endif
)
{
#endif
)
{
+ int status;
+
if ((pid = fork ()) == -1)
{
/* error */
if ((pid = fork ()) == -1)
{
/* error */
@@
-661,19
+664,24
@@
int main (int argc, char **argv)
close (1);
close (0);
close (1);
close (0);
- if (open ("/dev/null", O_RDWR) != 0)
+ status = open ("/dev/null", O_RDWR);
+ if (status != 0)
{
{
- ERROR ("Error: Could not connect `STDIN' to `/dev/null'
"
);
+ ERROR ("Error: Could not connect `STDIN' to `/dev/null'
(status %d)", status
);
return (1);
}
return (1);
}
- if (dup (0) != 1)
+
+ status = dup (0);
+ if (status != 1)
{
{
- ERROR ("Error: Could not connect `STDOUT' to `/dev/null'
"
);
+ ERROR ("Error: Could not connect `STDOUT' to `/dev/null'
(status %d)", status
);
return (1);
}
return (1);
}
- if (dup (0) != 2)
+
+ status = dup (0);
+ if (status != 2)
{
{
- ERROR ("Error: Could not connect `STDERR' to `/dev/null'
"
);
+ ERROR ("Error: Could not connect `STDERR' to `/dev/null'
, (status %d)", status
);
return (1);
}
} /* if (daemonize) */
return (1);
}
} /* if (daemonize) */
@@
-716,12
+724,19
@@
int main (int argc, char **argv)
/*
* run the actual loops
*/
/*
* run the actual loops
*/
- do_init ();
+ if (do_init () != 0)
+ {
+ ERROR ("Error: one or more plugin init callbacks failed.");
+ exit_status = 1;
+ }
if (test_readall)
{
if (plugin_read_all_once () != 0)
if (test_readall)
{
if (plugin_read_all_once () != 0)
+ {
+ ERROR ("Error: one or more plugin read callbacks failed.");
exit_status = 1;
exit_status = 1;
+ }
}
else
{
}
else
{
@@
-732,7
+747,11
@@
int main (int argc, char **argv)
/* close syslog */
INFO ("Exiting normally.");
/* close syslog */
INFO ("Exiting normally.");
- do_shutdown ();
+ if (do_shutdown () != 0)
+ {
+ ERROR ("Error: one or more plugin shutdown callbacks failed.");
+ exit_status = 1;
+ }
#if COLLECT_DAEMON
if (daemonize)
#if COLLECT_DAEMON
if (daemonize)