char pcap_error[PCAP_ERRBUF_SIZE];
struct bpf_program fp;
- struct pollfd poll_fds[1];
int status;
/* Don't block any signals */
pcap_obj = pcap_open_live (pcap_device,
PCAP_SNAPLEN,
0 /* Not promiscuous */,
- 0 /* no read timeout */,
+ atoi (COLLECTD_STEP),
pcap_error);
if (pcap_obj == NULL)
{
dnstop_set_pcap_obj (pcap_obj);
dnstop_set_callback (dns_child_callback);
- /* Set up poll object */
- poll_fds[0].fd = pcap_fileno (pcap_obj);
- poll_fds[0].events = POLLIN | POLLPRI;
-
- while (42)
- {
- DBG ("poll (...)");
- status = poll (poll_fds, 1, -1 /* wait forever for a change */);
-
- /* Signals are not caught, but this is very handy when
- * attaching to the process with a debugger. -octo */
- if ((status < 0) && (errno == EINTR))
- {
- errno = 0;
- continue;
- }
-
- if (status < 0)
- {
- syslog (LOG_ERR, "dns plugin: poll(2) failed: %s",
- strerror (errno));
- break;
- }
-
- if (poll_fds[0].revents & (POLLERR | POLLHUP | POLLNVAL))
- {
- DBG ("pcap-device closed. Exiting.");
- syslog (LOG_ERR, "dns plugin: pcap-device closed. Exiting.");
- break;
- }
- else if (poll_fds[0].revents & (POLLIN | POLLPRI))
- {
- status = pcap_dispatch (pcap_obj,
- 10 /* Only handle 10 packets at a time */,
- handle_pcap /* callback */,
- NULL /* Whatever this means.. */);
- if (status < 0)
- {
- DBG ("pcap_dispatch failed: %s", pcap_geterr (pcap_obj));
- syslog (LOG_ERR, "dns plugin: pcap_dispatch failed: %s",
- pcap_geterr (pcap_obj));
- break;
- }
- }
- } /* while (42) */
+ status = pcap_loop (pcap_obj,
+ -1 /* loop forever */,
+ handle_pcap /* callback */,
+ NULL /* Whatever this means.. */);
+ if (status < 0)
+ syslog (LOG_ERR, "dns plugin: Listener thread is exiting "
+ "abnormally: %s", pcap_geterr (pcap_obj));
DBG ("child is exiting");
pcap_close (pcap_obj);
+ listen_thread_init = 0;
pthread_exit (NULL);
return (NULL);
/* 256 bytes ought to be enough for anybody ;-) */
#define BUFSIZE 256
-#define SOCK_PATH "/tmp/.collectd-email"
+#ifndef COLLECTD_SOCKET_PREFIX
+# define COLLECTD_SOCKET_PREFIX "/tmp/.collectd-"
+#endif /* COLLECTD_SOCKET_PREFIX */
+
+#define SOCK_PATH COLLECTD_SOCKET_PREFIX"email"
#define MAX_CONNS 5
#define MAX_CONNS_LIMIT 16384
/* thread managing "client" connections */
static pthread_t connector;
+static int connector_socket;
/* tell the connector thread that a collector is available */
static pthread_cond_t collector_available = PTHREAD_COND_INITIALIZER;
static void *open_connection (void *arg)
{
- int local = 0;
-
struct sockaddr_un addr;
/* create UNIX socket */
errno = 0;
- if (-1 == (local = socket (PF_UNIX, SOCK_STREAM, 0))) {
+ if (-1 == (connector_socket = socket (PF_UNIX, SOCK_STREAM, 0))) {
disabled = 1;
syslog (LOG_ERR, "socket() failed: %s", strerror (errno));
pthread_exit ((void *)1);
unlink (addr.sun_path);
errno = 0;
- if (-1 == bind (local, (struct sockaddr *)&addr,
+ if (-1 == bind (connector_socket, (struct sockaddr *)&addr,
offsetof (struct sockaddr_un, sun_path)
+ strlen(addr.sun_path))) {
disabled = 1;
}
errno = 0;
- if (-1 == listen (local, 5)) {
+ if (-1 == listen (connector_socket, 5)) {
disabled = 1;
syslog (LOG_ERR, "listen() failed: %s", strerror (errno));
pthread_exit ((void *)1);
do {
errno = 0;
- if (-1 == (remote = accept (local, NULL, NULL))) {
+ if (-1 == (remote = accept (connector_socket, NULL, NULL))) {
if (EINTR != errno) {
disabled = 1;
syslog (LOG_ERR, "accept() failed: %s", strerror (errno));
return;
} /* static void email_init (void) */
+#if EMAIL_HAVE_READ
+static void email_shutdown (void)
+{
+ collector_t *ptr;
+
+ if (disabled)
+ return;
+
+ close (connector_socket);
+ pthread_kill (connector, SIGTERM);
+
+ pthread_mutex_lock (&active_mutex);
+
+ for (ptr = active.head; NULL != ptr; ptr = ptr->next) {
+ close (ptr->socket);
+ pthread_kill (ptr->thread, SIGTERM);
+ }
+
+ pthread_mutex_unlock (&active_mutex);
+
+ unlink (SOCK_PATH);
+ return;
+} /* static void email_shutdown (void) */
+#endif /* EMAIL_HAVE_READ */
+
static void count_write (char *host, char *inst, char *val)
{
char file[BUFSIZE] = "";
plugin_register ("email_spam_score", NULL, NULL, score_write);
plugin_register ("email_spam_check", NULL, NULL, check_write);
#if EMAIL_HAVE_READ
+ plugin_register_shutdown (MODULE_NAME, email_shutdown);
cf_register (MODULE_NAME, email_config, config_keys, config_keys_num);
#endif /* EMAIL_HAVE_READ */
return;
*/
static int sensor_extended_naming = 0;
-#ifdef HAVE_LIBSENSORS
+#if SENSORS_HAVE_READ
typedef struct featurelist
{
const sensors_chip_name *chip;
} featurelist_t;
featurelist_t *first_feature = NULL;
-#endif /* defined (HAVE_LIBSENSORS) */
+#endif /* if SENSORS_HAVE_READ */
static int sensors_config (char *key, char *value)
{
static void collectd_sensors_init (void)
{
-#ifdef HAVE_LIBSENSORS
+#if SENSORS_HAVE_READ
FILE *fh;
featurelist_t *last_feature = NULL;
featurelist_t *new_feature;
if (first_feature == NULL)
sensors_cleanup ();
-#endif /* defined(HAVE_LIBSENSORS) */
+#endif /* if SENSORS_HAVE_READ */
return;
}
+static void sensors_shutdown (void)
+{
+#if SENSORS_HAVE_READ
+ featurelist_t *thisft = first_feature;
+ featurelist_t *nextft;
+
+ while (thisft != NULL)
+ {
+ nextft = thisft->next;
+ sfree (thisft);
+ thisft = nextft;
+ }
+
+ sensors_cleanup ();
+#endif /* if SENSORS_HAVE_READ */
+
+ ignorelist_free (sensor_list);
+}
+
static void sensors_voltage_write (char *host, char *inst, char *val)
{
char file[BUFSIZE];
{
plugin_register (MODULE_NAME, collectd_sensors_init, sensors_read, sensors_write);
plugin_register (MODULE_NAME_VOLTAGE, NULL, NULL, sensors_voltage_write);
+ plugin_register_shutdown (MODULE_NAME, sensors_shutdown);
cf_register (MODULE_NAME, sensors_config, config_keys, config_keys_num);
}
{
int i;
- for (i = 0; i < 4; i++)
- if (a->s6_addr32[i] != b->s6_addr32[i])
+ assert (sizeof (struct in6_addr) == 16);
+
+ for (i = 0; i < 16; i++)
+ if (a->s6_addr[i] != b->s6_addr[i])
break;
- if (i >= 4)
+ if (i >= 16)
return (0);
- return (a->s6_addr32[i] > b->s6_addr32[i] ? 1 : -1);
+ return (a->s6_addr[i] > b->s6_addr[i] ? 1 : -1);
} /* int cmp_addrinfo */
static inline int ignore_list_match (const struct in6_addr *addr)
{
if (ai_ptr->ai_family == AF_INET)
{
- addr.s6_addr32[0] = 0;
- addr.s6_addr32[1] = 0;
- addr.s6_addr32[2] = htonl (0x0000FFFF);
- addr.s6_addr32[3] = ((struct sockaddr_in *) ai_ptr->ai_addr)->sin_addr.s_addr;
+ memset (&addr, '\0', sizeof (addr));
+ addr.s6_addr[10] = 0xFF;
+ addr.s6_addr[11] = 0xFF;
+ memcpy (addr.s6_addr + 12, &((struct sockaddr_in *) ai_ptr->ai_addr)->sin_addr, 4);
ignore_list_add (&addr);
}
memset (ia, 0, sizeof (struct in6_addr));
if ((AF_INET == family) && (sizeof (uint32_t) == buf_len))
{
- ia->s6_addr32[2] = htonl (0x0000FFFF);
- ia->s6_addr32[3] = *((uint32_t *) buf);
+ ia->s6_addr[10] = 0xFF;
+ ia->s6_addr[11] = 0xFF;
+ memcpy (ia->s6_addr + 12, buf, buf_len);
}
else if ((AF_INET6 == family) && (sizeof (struct in6_addr) == buf_len))
{
return 1;
}
+#if HAVE_NET_IF_PPP_H
static int
handle_ppp(const u_char * pkt, int len)
{
memcpy(buf, pkt, len);
return handle_ip((struct ip *) buf, len);
}
+#endif /* HAVE_NET_IF_PPP_H */
static int
handle_null(const u_char * pkt, int len)
case DLT_EN10MB:
status = handle_ether (pkt, hdr->caplen);
break;
+#if HAVE_NET_IF_PPP_H
case DLT_PPP:
status = handle_ppp (pkt, hdr->caplen);
break;
+#endif
#ifdef DLT_LOOP
case DLT_LOOP:
status = handle_loop (pkt, hdr->caplen);
case DLT_EN10MB:
handle_datalink = handle_ether;
break;
-#if USE_PPP
+#if HAVE_NET_IF_PPP_H
case DLT_PPP:
handle_datalink = handle_ppp;
break;
return 0;
} /* static int main(int argc, char *argv[]) */
#endif
+/*
+ * vim:shiftwidth=4:tabstop=8:softtabstop=4
+ */