Skip to content

Commit

Permalink
Fix #137: Graceful exit on signal during run
Browse files Browse the repository at this point in the history
  • Loading branch information
jelu committed Jan 25, 2017
1 parent 4e9ba7a commit 2a07185
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,23 +1024,28 @@ Pcap_run(void)
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) {
dsyslogf(LOG_ERR, "libpcap error [%d]: %s (%s)",
pcap_thread_status(&pcap_thread),
pcap_statustostr(pcap_thread_status(&pcap_thread)),
pcap_thread_errbuf(&pcap_thread)
);
if (err == PCAP_THREAD_ERRNO && errno == EINTR && sig_while_processing) {
dsyslog(LOG_INFO, "pcap thread run interruped by signal");
}
else if (err == PCAP_THREAD_ERRNO) {
char errbuf[512];
dsyslogf(LOG_ERR, "system error [%d]: %s (%s)\n",
errno,
dsc_strerror(errno, errbuf, sizeof(errbuf)),
pcap_thread_errbuf(&pcap_thread)
);
else {
dsyslogf(LOG_ERR, "unable to pcap thread run: %s", pcap_thread_strerr(err));
if (err == PCAP_THREAD_EPCAP) {
dsyslogf(LOG_ERR, "libpcap error [%d]: %s (%s)",
pcap_thread_status(&pcap_thread),
pcap_statustostr(pcap_thread_status(&pcap_thread)),
pcap_thread_errbuf(&pcap_thread)
);
}
else if (err == PCAP_THREAD_ERRNO) {
char errbuf[512];
dsyslogf(LOG_ERR, "system error [%d]: %s (%s)\n",
errno,
dsc_strerror(errno, errbuf, sizeof(errbuf)),
pcap_thread_errbuf(&pcap_thread)
);
}
return 0;
}
return 0;
}

/* TODO: Remove before release */
Expand All @@ -1050,6 +1055,9 @@ Pcap_run(void)
dsyslogf(LOG_INFO, "Ran to %lu.%lu", now.tv_sec, now.tv_usec);
}

if (sig_while_processing)
finish_ts = last_ts;

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) {
Expand All @@ -1061,9 +1069,6 @@ Pcap_run(void)
}
return 0;
}

if (sig_while_processing)
finish_ts = last_ts;
}
tcpList_remove_older_than(last_ts.tv_sec - MAX_TCP_IDLE);
return 1;
Expand Down

0 comments on commit 2a07185

Please sign in to comment.