]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Separate flushing the packet buffer from SIGINFO to SIGUSR2 670/head
authorGuy Lewin <[email protected]>
Sat, 7 Apr 2018 22:46:53 +0000 (01:46 +0300)
committerGuy Lewin <[email protected]>
Sat, 7 Apr 2018 22:46:53 +0000 (01:46 +0300)
tcpdump.1.in
tcpdump.c

index eced6958afd694573a904addfe591e7d58959333..e9831e2deb7487f1f58a4618f6b2edaf2300464d 100644 (file)
@@ -212,6 +212,10 @@ in order to use it) and will continue capturing packets. On platforms that
 do not support the SIGINFO signal, the same can be achieved by using the
 SIGUSR1 signal.
 .LP
+Using the SIGUSR2 signal along with the
+.B \-w
+flag will forcibly flush the packet buffer into the output file.
+.LP
 Reading packets from a network interface may require that you have
 special privileges; see the
 .B pcap (3PCAP)
index dbec2f8899b99253c63321834efc00cd898c667e..728328f771813e9848463edccf7d88a2b800aa12 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -148,6 +148,10 @@ The Regents of the University of California.  All rights reserved.\n";
 #define SIGNAL_REQ_INFO SIGUSR1
 #endif
 
+#if defined(HAVE_PCAP_DUMP_FLUSH) && defined(SIGUSR2)
+#define SIGNAL_FLUSH_PCAP SIGUSR2
+#endif
+
 static int Bflag;                      /* buffer size */
 #ifdef HAVE_PCAP_DUMP_FTELL64
 static int64_t Cflag;                  /* rotate dump files after this many bytes */
@@ -232,6 +236,10 @@ static void droproot(const char *, const char *);
 void requestinfo(int);
 #endif
 
+#ifdef SIGNAL_FLUSH_PCAP
+void flushpcap(int);
+#endif
+
 #ifdef _WIN32
     static HANDLE timer_handle = INVALID_HANDLE_VALUE;
     static void CALLBACK verbose_stats_dump(PVOID param, BOOLEAN timer_fired);
@@ -2273,6 +2281,9 @@ DIAG_ON_CLANG(assign-enum)
        if (RFileName == NULL)
                (void)setsignal(SIGNAL_REQ_INFO, requestinfo);
 #endif
+#ifdef SIGNAL_FLUSH_PCAP
+       (void)setsignal(SIGNAL_FLUSH_PCAP, flushpcap);
+#endif
 
        if (ndo->ndo_vflag > 0 && WFileName && !print) {
                /*
@@ -2905,11 +2916,14 @@ void requestinfo(int signo _U_)
                ++infoprint;
        else
                info(0);
-
-#ifdef HAVE_PCAP_DUMP_FLUSH
-       if (p != NULL)
-               pcap_dump_flush(p);
+}
 #endif
+
+#ifdef SIGNAL_FLUSH_PCAP
+void flushpcap(int signo _U_)
+{
+    if (p != NULL)
+        pcap_dump_flush(p);
 }
 #endif