ust-fd: Add close_range declaration
[lttng-ust.git] / libringbuffer / shm.c
index 10b3bcef110a979ce2169ccf10417e470e122ba9..00b3d129957b12581a913e95d5cd4af63246964e 100644 (file)
@@ -40,6 +40,7 @@
 #endif
 #include <helper.h>
 #include <ust-fd.h>
+#include "mmap.h"
 
 /*
  * Ensure we have the required amount of space available by writing 0
@@ -107,18 +108,11 @@ struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table,
        obj = &table->objects[table->allocated_len];
 
        /* wait_fd: create pipe */
-       ret = pipe(waitfd);
+       ret = pipe2(waitfd, O_CLOEXEC);
        if (ret < 0) {
                PERROR("pipe");
                goto error_pipe;
        }
-       for (i = 0; i < 2; i++) {
-               ret = fcntl(waitfd[i], F_SETFD, FD_CLOEXEC);
-               if (ret < 0) {
-                       PERROR("fcntl");
-                       goto error_fcntl;
-               }
-       }
        /* The write end of the pipe needs to be non-blocking */
        ret = fcntl(waitfd[1], F_SETFL, O_NONBLOCK);
        if (ret < 0) {
@@ -154,7 +148,7 @@ struct shm_object *_shm_object_table_alloc_shm(struct shm_object_table *table,
 
        /* memory_map: mmap */
        memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
-                         MAP_SHARED, shmfd, 0);
+                         MAP_SHARED | LTTNG_MAP_POPULATE, shmfd, 0);
        if (memory_map == MAP_FAILED) {
                PERROR("mmap");
                goto error_mmap;
@@ -200,18 +194,11 @@ struct shm_object *_shm_object_table_alloc_mem(struct shm_object_table *table,
                goto alloc_error;
 
        /* wait_fd: create pipe */
-       ret = pipe(waitfd);
+       ret = pipe2(waitfd, O_CLOEXEC);
        if (ret < 0) {
                PERROR("pipe");
                goto error_pipe;
        }
-       for (i = 0; i < 2; i++) {
-               ret = fcntl(waitfd[i], F_SETFD, FD_CLOEXEC);
-               if (ret < 0) {
-                       PERROR("fcntl");
-                       goto error_fcntl;
-               }
-       }
        /* The write end of the pipe needs to be non-blocking */
        ret = fcntl(waitfd[1], F_SETFL, O_NONBLOCK);
        if (ret < 0) {
@@ -327,11 +314,6 @@ struct shm_object *shm_object_table_append_shm(struct shm_object_table *table,
        obj->shm_fd = shm_fd;
        obj->shm_fd_ownership = 1;
 
-       ret = fcntl(obj->wait_fd[1], F_SETFD, FD_CLOEXEC);
-       if (ret < 0) {
-               PERROR("fcntl");
-               goto error_fcntl;
-       }
        /* The write end of the pipe needs to be non-blocking */
        ret = fcntl(obj->wait_fd[1], F_SETFL, O_NONBLOCK);
        if (ret < 0) {
@@ -341,7 +323,7 @@ struct shm_object *shm_object_table_append_shm(struct shm_object_table *table,
 
        /* memory_map: mmap */
        memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
-                         MAP_SHARED, shm_fd, 0);
+                         MAP_SHARED | LTTNG_MAP_POPULATE, shm_fd, 0);
        if (memory_map == MAP_FAILED) {
                PERROR("mmap");
                goto error_mmap;
@@ -377,11 +359,6 @@ struct shm_object *shm_object_table_append_mem(struct shm_object_table *table,
        obj->shm_fd = -1;
        obj->shm_fd_ownership = 0;
 
-       ret = fcntl(obj->wait_fd[1], F_SETFD, FD_CLOEXEC);
-       if (ret < 0) {
-               PERROR("fcntl");
-               goto error_fcntl;
-       }
        /* The write end of the pipe needs to be non-blocking */
        ret = fcntl(obj->wait_fd[1], F_SETFL, O_NONBLOCK);
        if (ret < 0) {
This page took 0.024529 seconds and 4 git commands to generate.