diff --git a/src/dns.c b/src/dns.c
index b2039a72102acba367b4522c964a946ab8a81a67..5e114b16da8e555d7e5c148735c2b35d986760c1 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
#if HAVE_LIBPCAP && HAVE_LIBPTHREAD
# include <pthread.h>
# include <pcap.h>
#if HAVE_LIBPCAP && HAVE_LIBPTHREAD
# include <pthread.h>
# include <pcap.h>
-# include <sys/poll.h>
+# include <poll.h>
# define DNS_HAVE_READ 1
#else
# define DNS_HAVE_READ 0
# define DNS_HAVE_READ 1
#else
# define DNS_HAVE_READ 0
char pcap_error[PCAP_ERRBUF_SIZE];
struct bpf_program fp;
char pcap_error[PCAP_ERRBUF_SIZE];
struct bpf_program fp;
- struct pollfd poll_fds[1];
int status;
/* Don't block any signals */
int status;
/* Don't block any signals */
pcap_obj = pcap_open_live (pcap_device,
PCAP_SNAPLEN,
0 /* Not promiscuous */,
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)
{
pcap_error);
if (pcap_obj == NULL)
{
dnstop_set_pcap_obj (pcap_obj);
dnstop_set_callback (dns_child_callback);
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);
DBG ("child is exiting");
pcap_close (pcap_obj);
+ listen_thread_init = 0;
pthread_exit (NULL);
return (NULL);
pthread_exit (NULL);
return (NULL);