/*
* 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);
if (fd < 0) {
char recv_fd[CMSG_SPACE(sizeof_fds)];
struct msghdr msg;
char dummy;
+ int i;
memset(&msg, 0, sizeof(msg));
ret = -1;
goto end;
}
+
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->shm_fd = shm_fd;
obj->shm_fd_ownership = 1;
- 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) {