Fix: move fsync after ftruncate
[lttng-ust.git] / libringbuffer / shm.c
index c4c651e4b925543e373e9b016398636be4c03293..ea946ea3f5e2a6d2e46d3297ebe925135164272e 100644 (file)
@@ -134,6 +134,15 @@ struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table,
                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;
 
@@ -153,6 +162,7 @@ struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table,
        return obj;
 
 error_mmap:
+error_fsync:
 error_ftruncate:
 error_zero_file:
 error_fcntl:
This page took 0.023089 seconds and 4 git commands to generate.