diff --git a/src/daemon.c b/src/daemon.c index b9fdcb1b..6b1a4ea2 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -368,7 +368,6 @@ main(int argc, char *argv[]) #endif int err; struct timeval now; - size_t usec_adjust; progname = xstrdup(strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0]); if (NULL == progname) @@ -531,43 +530,19 @@ main(int argc, char *argv[]) dsyslog(LOG_INFO, "Running"); do { - usec_adjust = 0; - useArena(); /* Initialize a memory arena for data collection. */ - if (break_start.tv_sec > 0) { + if (debug_flag && break_start.tv_sec > 0) { gettimeofday(&now, NULL); - /* TODO: Remove before release */ - dsyslogf(LOG_INFO, "break start %lu.%lu, now %lu.%lu", break_start.tv_sec, break_start.tv_usec, now.tv_sec, now.tv_usec); - - if (now.tv_sec == break_start.tv_sec) { - if (break_start.tv_usec < now.tv_usec) - usec_adjust = now.tv_usec - break_start.tv_usec; - else if (break_start.tv_usec > now.tv_usec) - dsyslog(LOG_INFO, "Time shift detected, not adjusting for inter-run processing"); - } - else if (now.tv_sec > break_start.tv_sec) { - usec_adjust = now.tv_sec - break_start.tv_sec; - if (usec_adjust > 1) { - dsyslogf(LOG_WARNING, "Large time shift detected, >%lu seconds, not adjusting for inter-run processing", usec_adjust); - usec_adjust = 0; - } - else { - usec_adjust = 1000000 - break_start.tv_usec + now.tv_usec; - if (usec_adjust > 950000) { - dsyslogf(LOG_INFO, "Inter-run processing is taking too long, %lu useconds, limiting adjustment", usec_adjust); - usec_adjust = 950000; - } - } - } - else - dsyslog(LOG_INFO, "Time shift detected, not adjusting for inter-run processing"); + dsyslogf(LOG_INFO, "inter-run processing delay: %ld ms", + (now.tv_usec - break_start.tv_usec) / 1000 + 1000 * (now.tv_sec - break_start.tv_sec)); } /* Indicate we might have reports to dump on exit */ have_reports = 1; - result = Pcap_run(usec_adjust); - gettimeofday(&break_start, NULL); + result = Pcap_run(); + if (debug_flag) + gettimeofday(&break_start, NULL); if (0 == fork()) { struct sigaction action; diff --git a/src/pcap-thread b/src/pcap-thread index 2cd7d900..f56d37c8 160000 --- a/src/pcap-thread +++ b/src/pcap-thread @@ -1 +1 @@ -Subproject commit 2cd7d900c432b07cf2df48dc3fc5bfe955290b2a +Subproject commit f56d37c81733760cd351fe693dadba4b72c59fed diff --git a/src/pcap.c b/src/pcap.c index 0f15f4df..3e1c43bd 100644 --- a/src/pcap.c +++ b/src/pcap.c @@ -931,11 +931,10 @@ void _stats(u_char* user, const struct pcap_stat* stats, const char* name, int d } int -Pcap_run(const size_t usec_adjust) +Pcap_run(void) { int i, err; extern uint64_t statistics_interval; - struct timeval timedrun = { 0, 0 }; for (i = 0; i < n_interfaces; i++) interfaces[i].pkts_captured = 0; @@ -1011,52 +1010,14 @@ Pcap_run(const size_t usec_adjust) gettimeofday(&last_ts, NULL); finish_ts.tv_sec = ((start_ts.tv_sec / statistics_interval) + 1) * statistics_interval; finish_ts.tv_usec = 0; - - /* - * Calculate timed run, add a second to start_ts because we wait - * the remaining useconds - */ - if ((start_ts.tv_sec + 1) % statistics_interval) - timedrun.tv_sec = statistics_interval - ((start_ts.tv_sec + 1) % statistics_interval); - else - timedrun.tv_sec = 0; - if (start_ts.tv_usec < 1000000) - timedrun.tv_usec = 1000000 - start_ts.tv_usec; - else - timedrun.tv_usec = 0; - - /* TODO: Remove before release */ - dsyslogf(LOG_INFO, "Timed run for %lu.%lu seconds", timedrun.tv_sec, timedrun.tv_usec); - - /* - * Adjust for inter-run processing time - */ - if (usec_adjust < 1000000) { - if (timedrun.tv_usec < usec_adjust) { - if (timedrun.tv_sec) { - timedrun.tv_sec--; - timedrun.tv_usec = 1000000 - (usec_adjust - timedrun.tv_usec); - } - else { - timedrun.tv_sec = 0; - timedrun.tv_usec = 0; - } - } - else - timedrun.tv_usec -= usec_adjust; - - /* TODO: Remove before release */ - dsyslogf(LOG_INFO, "Adjusted to %lu.%lu seconds", timedrun.tv_sec, timedrun.tv_usec); - } - else { - dsyslogf(LOG_ERR, "Adjustment invalid, %lu larger then 999999 useconds", usec_adjust); - } - - if ((err = pcap_thread_set_timedrun(&pcap_thread, timedrun))) { + if ((err = pcap_thread_set_timedrun_to(&pcap_thread, finish_ts))) { dsyslogf(LOG_ERR, "unable to set pcap thread timed run: %s", pcap_thread_strerr(err)); exit(1); } + /* TODO: Remove before release */ + dsyslogf(LOG_INFO, "Timed run set to %lu.%lu, now %lu.%lu", finish_ts.tv_sec, finish_ts.tv_usec, start_ts.tv_sec, start_ts.tv_usec); + if ((err = pcap_thread_run(&pcap_thread))) { dsyslogf(LOG_ERR, "unable to pcap thread run: %s", pcap_thread_strerr(err)); if (err == PCAP_THREAD_EPCAP) { @@ -1077,6 +1038,13 @@ Pcap_run(const size_t usec_adjust) exit(1); } + /* TODO: Remove before release */ + { + struct timeval now = { 0, 0 }; + gettimeofday(&now, 0); + dsyslogf(LOG_INFO, "Ran to %lu.%lu", now.tv_sec, now.tv_usec); + } + if ((err = pcap_thread_stats(&pcap_thread, _stats, 0))) { dsyslogf(LOG_ERR, "unable to get pcap thread stats: %s", pcap_thread_strerr(err)); if (err == PCAP_THREAD_EPCAP) { diff --git a/src/pcap.h b/src/pcap.h index f6ca1e12..a4249e88 100644 --- a/src/pcap.h +++ b/src/pcap.h @@ -40,7 +40,7 @@ #define __dsc_pcap_h void Pcap_init(const char *device, int promisc, int monitor, int immediate, int threads, int buffer_size); -int Pcap_run(const size_t usec_adjust); +int Pcap_run(); void Pcap_stop(void); void Pcap_close(void); int Pcap_start_time(void);