X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fdaemon%2Fcollectd.c;h=df238e710ad532f686f60764b4f10abf416fb6ce;hb=2b4da1f36e67a617cf742d667ad3b922a219f7a6;hp=cffb9a5fbb40a3567729deb544d5777832249c34;hpb=bf1613564dfcb0a517b77d658a844ea37b45803f;p=collectd.git diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index cffb9a5f..df238e71 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -32,7 +32,6 @@ #include "configfile.h" #include -#include #include #include @@ -197,8 +196,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) @@ -458,7 +459,11 @@ int notify_systemd (void) 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); +#endif if (fd < 0) { char errbuf[1024]; ERROR ("creating UNIX socket failed: %s", @@ -476,7 +481,6 @@ int notify_systemd (void) } 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 @@ -486,11 +490,6 @@ int notify_systemd (void) 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)