diff options
Diffstat (limited to 'filemon/filemon_dev.c')
| -rw-r--r-- | filemon/filemon_dev.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/filemon/filemon_dev.c b/filemon/filemon_dev.c index 741edc7c25ea..f605061f5c67 100644 --- a/filemon/filemon_dev.c +++ b/filemon/filemon_dev.c @@ -1,4 +1,4 @@ -/* $NetBSD: filemon_dev.c,v 1.9 2022/03/04 23:17:16 sjg Exp $ */ +/* $NetBSD: filemon_dev.c,v 1.10 2026/07/03 03:34:25 sjg Exp $ */ /* * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -123,6 +123,19 @@ filemon_close(struct filemon *F) { int error = 0; +#ifdef FILEMON_FLUSH_IOCTL + /* + * Ask the kernel to write the footer and flush the trailing records to + * the output file *now*, synchronously, before we close the device. + * Otherwise finalization happens only at device release, which the + * kernel defers until the last reference to the device is dropped; a + * child that transiently inherited this fd across a fork->exec window + * can hold that reference past our read of the output file, yielding a + * truncated .meta (records + "# Bye bye" footer missing). + */ + (void)ioctl(F->fd, FILEMON_FLUSH_IOCTL); +#endif + /* Close the filemon device fd. */ if (close(F->fd) == -1 && error == 0) error = errno; |
