X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust%2Flttng-ust-comm.c;fp=liblttng-ust%2Flttng-ust-comm.c;h=e8c85304e798b446ecf17110cc9e3fd70464527f;hb=5d32ea4466f42665808fe8cf7ac8b533cb512aee;hp=1c7584ddd51e84ed3d1d55015467101791bd4657;hpb=75b46fdf889cde49b02a7e15cae52e2e2d3e94bc;p=lttng-ust.git diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 1c7584dd..e8c85304 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -689,6 +689,30 @@ int get_wait_shm(struct sock_info *sock_info, size_t mmap_size) */ wait_shm_fd = shm_open(sock_info->wait_shm_path, O_RDONLY, 0); if (wait_shm_fd >= 0) { + int32_t tmp_read; + ssize_t len; + size_t bytes_read = 0; + + /* + * Try to read the fd. If unable to do so, try opening + * it in write mode. + */ + do { + len = read(wait_shm_fd, + &((char *) &tmp_read)[bytes_read], + sizeof(tmp_read) - bytes_read); + if (len > 0) { + bytes_read += len; + } + } while ((len < 0 && errno == EINTR) + || (len > 0 && bytes_read < sizeof(tmp_read))); + if (bytes_read != sizeof(tmp_read)) { + ret = close(wait_shm_fd); + if (ret) { + ERR("close wait_shm_fd"); + } + goto open_write; + } goto end; } else if (wait_shm_fd < 0 && errno != ENOENT) { /* @@ -699,9 +723,11 @@ int get_wait_shm(struct sock_info *sock_info, size_t mmap_size) ERR("Error opening shm %s", sock_info->wait_shm_path); goto end; } + +open_write: /* - * If the open failed because the file did not exist, try - * creating it ourself. + * If the open failed because the file did not exist, or because + * the file was not truncated yet, try creating it ourself. */ URCU_TLS(lttng_ust_nest_count)++; pid = fork();