X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Femail.c;h=869b7c36aa620cff5f7ae2f2d806d79868084eea;hb=1297a3723f6c5a79e8148e56c249a1aa7d3c6f35;hp=b4767554b433c83982685f684ee9232810c126c0;hpb=e1b0c447f57338706d45a485b40da7325faa4f34;p=collectd.git diff --git a/src/email.c b/src/email.c index b4767554..869b7c36 100644 --- a/src/email.c +++ b/src/email.c @@ -4,8 +4,7 @@ * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. + * Free Software Foundation; only version 2 of the License is applicable. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -40,24 +39,15 @@ #include "configfile.h" +#include + #if HAVE_LIBPTHREAD # include #endif -#if HAVE_SYS_SELECT_H -# include -#endif /* HAVE_SYS_SELECT_H */ - -#if HAVE_SYS_SOCKET_H -# include -#endif /* HAVE_SYS_SOCKET_H */ - -/* *sigh* glibc does not define UNIX_PATH_MAX in sys/un.h ... */ -#if HAVE_LINUX_UN_H -# include -#elif HAVE_SYS_UN_H -# include -#endif /* HAVE_LINUX_UN_H | HAVE_SYS_UN_H */ +#include +#include +#include /* some systems (e.g. Darwin) seem to not define UNIX_PATH_MAX at all */ #ifndef UNIX_PATH_MAX @@ -73,11 +63,7 @@ /* 256 bytes ought to be enough for anybody ;-) */ #define BUFSIZE 256 -#ifndef COLLECTD_SOCKET_PREFIX -# define COLLECTD_SOCKET_PREFIX "/tmp/.collectd-" -#endif /* COLLECTD_SOCKET_PREFIX */ - -#define SOCK_PATH COLLECTD_SOCKET_PREFIX"email" +#define SOCK_PATH LOCALSTATEDIR"/run/"PACKAGE_NAME"-email" #define MAX_CONNS 5 #define MAX_CONNS_LIMIT 16384 @@ -131,6 +117,7 @@ typedef struct { /* valid configuration file keys */ static const char *config_keys[] = { + "SocketFile", "SocketGroup", "SocketPerms", "MaxConns" @@ -138,6 +125,7 @@ static const char *config_keys[] = static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); /* socket configuration */ +static char *sock_file = SOCK_PATH; static char *sock_group = COLLECTD_GRP_NAME; static int sock_perms = S_IRWXU | S_IRWXG; static int max_conns = MAX_CONNS; @@ -183,7 +171,10 @@ static type_list_t check; */ static int email_config (const char *key, const char *value) { - if (0 == strcasecmp (key, "SocketGroup")) { + if (0 == strcasecmp (key, "SocketFile")) { + sock_file = sstrdup (value); + } + else if (0 == strcasecmp (key, "SocketGroup")) { sock_group = sstrdup (value); } else if (0 == strcasecmp (key, "SocketPerms")) { @@ -520,7 +511,7 @@ static void *open_connection (void *arg) addr.sun_family = AF_UNIX; - strncpy (addr.sun_path, SOCK_PATH, (size_t)(UNIX_PATH_MAX - 1)); + strncpy (addr.sun_path, sock_file, (size_t)(UNIX_PATH_MAX - 1)); addr.sun_path[UNIX_PATH_MAX - 1] = '\0'; unlink (addr.sun_path); @@ -567,12 +558,12 @@ static void *open_connection (void *arg) } else { - status = chown (SOCK_PATH, (uid_t) -1, grp->gr_gid); + status = chown (sock_file, (uid_t) -1, grp->gr_gid); if (status != 0) { char errbuf[1024]; log_warn ("chown (%s, -1, %i) failed: %s", - SOCK_PATH, (int) grp->gr_gid, + sock_file, (int) grp->gr_gid, sstrerror (errno, errbuf, sizeof (errbuf))); } } @@ -583,7 +574,7 @@ static void *open_connection (void *arg) } errno = 0; - if (0 != chmod (SOCK_PATH, sock_perms)) { + if (0 != chmod (sock_file, sock_perms)) { char errbuf[1024]; log_warn ("chmod() failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); @@ -726,7 +717,7 @@ static int email_shutdown (void) pthread_mutex_unlock (&conns_mutex); - unlink (SOCK_PATH); + unlink (sock_file); errno = 0; return (0); @@ -791,7 +782,8 @@ static int email_read (void) { type_t *ptr; - double sc; + double score_old; + int score_count_old; static type_list_t *cnt; static type_list_t *sz; @@ -840,13 +832,15 @@ static int email_read (void) /* spam score */ pthread_mutex_lock (&score_mutex); - sc = score; + score_old = score; + score_count_old = score_count; score = 0.0; score_count = 0; pthread_mutex_unlock (&score_mutex); - email_submit ("spam_score", "", sc); + if (score_count_old > 0) + email_submit ("spam_score", "", score_old); /* spam checks */ pthread_mutex_lock (&check_mutex);