/*
* 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;
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;
return fd;
error_connect:
-error_fcntl:
{
int closeret;
char recv_fd[CMSG_SPACE(sizeof_fds)];
struct msghdr msg;
char dummy;
- int i;
memset(&msg, 0, sizeof(msg));
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) {
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;
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) {
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) {
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) {