summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 55ffd0b)
raw | patch | inline | side by side (parent: 55ffd0b)
author | Florian Forster <octo@crystal.wlan.home.verplant.org> | |
Mon, 4 Dec 2006 21:47:34 +0000 (22:47 +0100) | ||
committer | Florian Forster <octo@crystal.wlan.home.verplant.org> | |
Mon, 4 Dec 2006 21:47:34 +0000 (22:47 +0100) |
Not only does this simplify things *a lot* on *BSD and Mac OS X, because you
can't always call `poll' on their filedescriptors, it also simplifies the code
a lot and thus removes potential error sources.
can't always call `poll' on their filedescriptors, it also simplifies the code
a lot and thus removes potential error sources.
src/dns.c | patch | blob | history |
diff --git a/src/dns.c b/src/dns.c
index b2039a72102acba367b4522c964a946ab8a81a67..cd068fb363744b05c06f637a53ec248bd4d48ea5 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
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);