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 <mathieu.desnoyers@efficios.com>
* 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)
}
written += retlen;
}
+ ret = fsync(fd);
+ if (ret) {
+ ret = (int) -errno;
+ goto error;
+ }
ret = 0;
error:
free(zeropage);