X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fustcomm.c;h=47f228b1de907e7b6ac8e829e4074205fdddc086;hb=a34c2ec061dd1aee434ad6c0a0a1d78876010d47;hp=319e84ac923530d790de9afd22ba595849399e31;hpb=c117e9884c3acc65408d8f65b2cd86a8511df1cc;p=lttng-ust.git diff --git a/src/common/ustcomm.c b/src/common/ustcomm.c index 319e84ac..47f228b1 100644 --- a/src/common/ustcomm.c +++ b/src/common/ustcomm.c @@ -1,7 +1,7 @@ /* * SPDX-License-Identifier: LGPL-2.1-only * - * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 EfficiOS Inc. * Copyright (C) 2011-2013 Mathieu Desnoyers */ @@ -60,9 +60,8 @@ int ustcomm_connect_unix_sock(const char *pathname, long timeout) /* * libust threads require the close-on-exec flag for all * resources so it does not leak file descriptors upon exec. - * SOCK_CLOEXEC is not used since it is linux specific. */ - fd = socket(PF_UNIX, SOCK_STREAM, 0); + fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd < 0) { PERROR("socket"); ret = -errno; @@ -77,18 +76,13 @@ int ustcomm_connect_unix_sock(const char *pathname, long timeout) WARN("Error setting connect socket send timeout"); } } - ret = fcntl(fd, F_SETFD, FD_CLOEXEC); - if (ret < 0) { - PERROR("fcntl"); - ret = -errno; - goto error_fcntl; - } memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; strncpy(sun.sun_path, pathname, sizeof(sun.sun_path)); sun.sun_path[sizeof(sun.sun_path) - 1] = '\0'; + DBG("Connecting to '%s'", sun.sun_path); ret = connect(fd, (struct sockaddr *) &sun, sizeof(sun)); if (ret < 0) { /* @@ -110,7 +104,6 @@ int ustcomm_connect_unix_sock(const char *pathname, long timeout) return fd; error_connect: -error_fcntl: { int closeret; @@ -416,7 +409,6 @@ ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) char recv_fd[CMSG_SPACE(sizeof_fds)]; struct msghdr msg; char dummy; - int i; memset(&msg, 0, sizeof(msg)); @@ -429,7 +421,7 @@ ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) msg.msg_controllen = sizeof(recv_fd); do { - ret = recvmsg(sock, &msg, 0); + ret = recvmsg(sock, &msg, MSG_CMSG_CLOEXEC); } while (ret < 0 && errno == EINTR); if (ret < 0) { if (errno != EPIPE && errno != ECONNRESET) { @@ -475,15 +467,6 @@ ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) memcpy(fds, CMSG_DATA(cmsg), sizeof_fds); - /* Set FD_CLOEXEC */ - for (i = 0; i < nb_fd; i++) { - ret = fcntl(fds[i], F_SETFD, FD_CLOEXEC); - if (ret < 0) { - PERROR("fcntl failed to set FD_CLOEXEC on fd %d", - fds[i]); - } - } - ret = nb_fd; end: return ret; @@ -998,7 +981,7 @@ int serialize_dynamic_type(struct lttng_ust_session *session, strncpy(uf->name, field_name, LTTNG_UST_ABI_SYM_NAME_LEN); uf->name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0'; - uf->type.atype = lttng_ust_ctl_atype_variant; + uf->type.atype = lttng_ust_ctl_atype_variant_nestable; uf->type.u.variant_nestable.nr_choices = nr_choices; strncpy(uf->type.u.variant_nestable.tag_name, tag_field_name, @@ -1727,7 +1710,7 @@ int ustcomm_register_channel(int sock, } /* - * Set socket reciving timeout. + * Set socket receiving timeout. */ int ustcomm_setsockopt_rcv_timeout(int sock, unsigned int msec) {