Move fsync after ftruncate to ensure we sync up all metadata after the
entire initialization of the buffer.
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);
PERROR("ftruncate");
goto error_ftruncate;
}
+ /*
+ * Also ensure the file metadata is synced with the storage by using
+ * fsync(2).
+ */
+ ret = fsync(shmfd);
+ if (ret) {
+ PERROR("fsync");
+ goto error_fsync;
+ }
obj->shm_fd_ownership = 0;
obj->shm_fd = shmfd;
return obj;
error_mmap:
+error_fsync:
error_ftruncate:
error_zero_file:
error_fcntl: