From 429dadf0e28fe24be158ddb76d09f5f2308b6467 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 23 Aug 2017 08:17:48 -0700 Subject: [PATCH] Fix: sync buffer file metadata on buffer allocation Synchronizing the file metadata on disk after zeroing the whole file (on buffer allocation) will make the crash extraction feature (--shm-path create option) more robust. It ensures the content of the file metadata backing the buffers does not have to be updated while tracing into the memory map. Therefore, the on-disk metadata will never be out of sync at the point where a system crash occurs. Signed-off-by: Mathieu Desnoyers --- libringbuffer/shm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libringbuffer/shm.c b/libringbuffer/shm.c index c4c651e4..8ac321e3 100644 --- a/libringbuffer/shm.c +++ b/libringbuffer/shm.c @@ -39,6 +39,9 @@ * Ensure we have the required amount of space available by writing 0 * into the entire buffer. Not doing so can trigger SIGBUS when going * beyond the available shm space. + * + * Also ensure the file metadata is synced with the storage by using + * fsync(2). */ static int zero_file(int fd, size_t len) @@ -67,6 +70,11 @@ int zero_file(int fd, size_t len) } written += retlen; } + ret = fsync(fd); + if (ret) { + ret = (int) -errno; + goto error; + } ret = 0; error: free(zeropage); -- 2.34.1