#include <unistd.h>
#include <assert.h>
#include <errno.h>
+#include <fcntl.h>
#include <ust-comm.h>
* 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 | SOCK_CLOEXEC, 0);
+ fd = socket(PF_UNIX, SOCK_STREAM, 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;
return fd;
error_connect:
+error_fcntl:
close(fd);
error:
return ret;
*/
ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len)
{
- struct msghdr msg = { 0 };
+ struct msghdr msg;
struct iovec iov[1];
ssize_t ret = -1;
+ memset(&msg, 0, sizeof(msg));
+
iov[0].iov_base = buf;
iov[0].iov_len = 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");
}
*/
ssize_t ustcomm_send_unix_sock(int sock, void *buf, size_t len)
{
- struct msghdr msg = { 0 };
+ struct msghdr msg;
struct iovec iov[1];
ssize_t ret = -1;
+ memset(&msg, 0, sizeof(msg));
+
iov[0].iov_base = buf;
iov[0].iov_len = len;
msg.msg_iov = iov;
* 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");
}
{
int ret;
- /* Shutdown receptions and transmissions */
- ret = shutdown(sock, SHUT_RDWR);
+ ret = close(sock);
if (ret < 0) {
- perror("shutdown");
+ perror("close");
}
return ret;
*/
ssize_t ustcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len)
{
- struct msghdr msg = { 0 };
+ struct msghdr msg;
struct cmsghdr *cmptr;
struct iovec iov[1];
ssize_t ret = -1;
unsigned int sizeof_fds = nb_fd * sizeof(int);
char tmp[CMSG_SPACE(sizeof_fds)];
+ memset(&msg, 0, sizeof(msg));
+
/*
* Note: the consumerd receiver only supports receiving one FD per
* message.
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");
}
int data_fd;
struct cmsghdr *cmsg;
char recv_fd[CMSG_SPACE(sizeof(int))];
- struct msghdr msg = { 0 };
+ struct msghdr msg;
union {
unsigned char vc[4];
int vi;
} tmp;
int i;
+ memset(&msg, 0, sizeof(msg));
+
/* Prepare to receive the structures */
iov[0].iov_base = &data_fd;
iov[0].iov_len = sizeof(data_fd);
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)) {
- fprintf(stderr, "Received %d bytes, expected %ld", ret, sizeof(data_fd));
+ fprintf(stderr, "Received %d bytes, expected %zd", ret, sizeof(data_fd));
goto end;
}
cmsg = CMSG_FIRSTHDR(&msg);