X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust-comm%2Flttng-ust-comm.c;h=2332dbf1a383d2b2b6e1500fb604039e53ab72e9;hb=9d36f30e825135d8fbb3ba6cb31ab10aa938b135;hp=7e55cff556c6ced0314329401fdbe866480cf160;hpb=4171df999bf0c0c552fa35cea9a12fa4d82faae6;p=lttng-ust.git diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index 7e55cff5..2332dbf1 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -29,7 +29,6 @@ #include #include #include -#include #include @@ -120,17 +119,12 @@ int ustcomm_connect_unix_sock(const char *pathname) * libust threads require the close-on-exec flag for all * resources so it does not leak file descriptors upon exec. */ - fd = socket(PF_UNIX, SOCK_STREAM, 0); + fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); if (fd < 0) { perror("socket"); ret = fd; goto error; } - ret = fcntl(fd, F_SETFD, FD_CLOEXEC); - if (ret < 0) { - perror("fcntl"); - goto error_fcntl; - } memset(&sun, 0, sizeof(sun)); sun.sun_family = AF_UNIX; @@ -150,7 +144,6 @@ int ustcomm_connect_unix_sock(const char *pathname) return fd; error_connect: -error_fcntl: close(fd); error: return ret; @@ -255,8 +248,10 @@ ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) msg.msg_iov = iov; msg.msg_iovlen = 1; - ret = recvmsg(sock, &msg, 0); - if (ret < 0) { + do { + ret = recvmsg(sock, &msg, 0); + } while (ret < 0 && errno == EINTR); + if (ret < 0 && errno != EPIPE) { perror("recvmsg"); } @@ -289,8 +284,10 @@ ssize_t ustcomm_send_unix_sock(int sock, void *buf, size_t len) * by ignoring SIGPIPE, but we don't have this luxury on the * libust side. */ - ret = sendmsg(sock, &msg, MSG_NOSIGNAL); - if (ret < 0) { + do { + ret = sendmsg(sock, &msg, MSG_NOSIGNAL); + } while (ret < 0 && errno == EINTR); + if (ret < 0 && errno != EPIPE) { perror("sendmsg"); } @@ -306,10 +303,9 @@ int ustcomm_close_unix_sock(int sock) { int ret; - /* Shutdown receptions and transmissions */ - ret = shutdown(sock, SHUT_RDWR); + ret = close(sock); if (ret < 0) { - perror("shutdown"); + perror("close"); } return ret; @@ -353,8 +349,10 @@ ssize_t ustcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, msg.msg_iov = iov; msg.msg_iovlen = 1; - ret = sendmsg(sock, &msg, 0); - if (ret < 0) { + do { + ret = sendmsg(sock, &msg, MSG_NOSIGNAL); + } while (ret < 0 && errno == EINTR); + if (ret < 0 && errno != EPIPE) { perror("sendmsg"); } @@ -469,8 +467,13 @@ int ustcomm_recv_fd(int sock) msg.msg_control = recv_fd; msg.msg_controllen = sizeof(recv_fd); - if ((ret = recvmsg(sock, &msg, 0)) < 0) { - perror("recvmsg"); + do { + ret = recvmsg(sock, &msg, 0); + } while (ret < 0 && errno == EINTR); + if (ret < 0) { + if (errno != EPIPE) { + perror("recvmsg"); + } goto end; } if (ret != sizeof(data_fd)) {