]> The Tcpdump Group git mirrors - tcpslice/commitdiff
Use posix_fadvise() on input files if available.
authorDenis Ovsienko <[email protected]>
Sun, 26 Mar 2023 16:37:29 +0000 (17:37 +0100)
committerDenis Ovsienko <[email protected]>
Sun, 26 Mar 2023 16:40:43 +0000 (17:40 +0100)
Let's confirm this works as expected before trying the same elsewhere.

CHANGES
configure.ac
tcpslice.c

diff --git a/CHANGES b/CHANGES
index 4511e00cd048a85469cf765966c0d5e4b2a10714..c5a6465d6323c62d55b78f727e870619ec6cacf3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,7 @@ v1.7 ...
 - Fix a build error on Haiku.
 - Do the version number the same way as in tcpdump and libpcap.
 - Lose unused missing/strlcpy.c.
+- Use posix_fadvise() on input files if available.
 
 v1.6 Thu 20 Oct 21:22:28 BST 2022
 
index c2e22133d2a4efddcb5c5203370aeb4b96acd83c..49bd2606aac88e8f4923a0eda22c7a6eaddce7c5 100644 (file)
@@ -38,6 +38,9 @@ AC_CHECK_HEADERS(fcntl.h)
 AC_SYS_LARGEFILE
 AC_FUNC_FSEEKO
 
+# Haiku, OpenBSD, Solaris 9 and Solaris 10 don't have posix_fadvise().
+AC_CHECK_FUNCS([posix_fadvise])
+
 AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
 
 AC_MSG_CHECKING([whether to enable the instrument functions code])
index e450b8c57dbaf251b29534431771fe6885210ce6..e4aa982c8a6fa2936dc5350db975324c3d42733b 100644 (file)
@@ -781,6 +781,15 @@ open_files(char *filenames[], const int numfiles)
                s->p = pcap_open_offline(s->filename, errbuf);
                if (! s->p)
                        error( "bad pcap file %s: %s", s->filename, errbuf );
+
+#ifdef HAVE_POSIX_FADVISE
+               int padv_err, fd = fileno(pcap_file(s->p));
+               if (0 != (padv_err = posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM)))
+                       warning("warning: posix_fadvise() failed: %s", strerror(padv_err));
+               if (0 != (padv_err = posix_fadvise(fd, 0, 0, POSIX_FADV_NOREUSE)))
+                       warning("warning: posix_fadvise() failed: %s", strerror(padv_err));
+#endif
+
                if (track_sessions)
                        sessions_nids_init(s->p);