socklen_t credsz = sizeof(cred);
ret = LXC_MAINLOOP_ERROR;
- clientfd = accept(fd, NULL, 0);
+ clientfd = accept4(fd, NULL, 0, SOCK_CLOEXEC);
if (clientfd < 0) {
SYSERROR("Failed to accept connection for client file descriptor %d", fd);
goto out;
}
- if (fcntl(clientfd, F_SETFD, FD_CLOEXEC)) {
- SYSERROR("Failed to set FD_CLOEXEC on client socket connection %d", clientfd);
- goto err1;
- }
-
if (getsockopt(clientfd, SOL_SOCKET, SO_PEERCRED, &cred, &credsz)) {
SYSERROR("Failed to get credentials on client socket connection %d", clientfd);
goto err1;
__do_close int connection = -EBADF;
int opt = 1, ret = -1;
- connection = accept(fd, NULL, 0);
+ connection = accept4(fd, NULL, 0, SOCK_CLOEXEC);
if (connection < 0)
return log_error_errno(LXC_MAINLOOP_ERROR, errno, "Failed to accept connection to run command");
- ret = fcntl(connection, F_SETFD, FD_CLOEXEC);
- if (ret < 0)
- return log_error_errno(ret, errno, "Failed to set close-on-exec on incoming command connection");
-
ret = setsockopt(connection, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt));
if (ret < 0)
return log_error_errno(ret, errno, "Failed to enable necessary credentials on command socket");
return log_error_errno(-1, errno, "Failed to create command socket %s", &path[1]);
}
- ret = fcntl(fd, F_SETFD, FD_CLOEXEC);
- if (ret < 0)
- return log_error_errno(-1, errno, "Failed to set FD_CLOEXEC on command socket file descriptor");
-
return log_trace(move_fd(fd), "Created abstract unix socket \"%s\"", &path[1]);
}