aboutgitcodebugslistschat
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/util.c b/util.c
index 3e93d47..c492f90 100644
--- a/util.c
+++ b/util.c
@@ -34,6 +34,7 @@
#include "passt.h"
#include "packet.h"
#include "log.h"
+#include "pcap.h"
#ifdef HAS_GETRANDOM
#include <sys/random.h>
#endif
@@ -1045,3 +1046,17 @@ void abort_with_msg(const char *fmt, ...)
*/
abort();
}
+
+/**
+ * fsync_pcap_and_log() - Flush pcap and log files as needed
+ *
+ * #syscalls fsync
+ */
+void fsync_pcap_and_log(void)
+{
+ if (pcap_fd != -1 && fsync(pcap_fd))
+ warn_perror("Failed to flush pcap file, it might be truncated");
+
+ if (log_file != -1)
+ (void)fsync(log_file);
+}