]> git.proxmox.com Git - mirror_lxc.git/commitdiff
tree-wide: convert fcntl(FD_CLOEXEC) to SOCK_CLOEXEC
authorAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Fri, 17 Mar 2023 12:43:34 +0000 (13:43 +0100)
committerAlexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Fri, 17 Mar 2023 12:43:34 +0000 (13:43 +0100)
- replace accept() + fcntl(FD_CLOEXEC) with accept4(..., SOCK_CLOEXEC)
- remove fcntl(FD_CLOEXEC) in lxc_server_init() as we already set
SOCK_CLOEXEC in lxc_abstract_unix_open().

See also: ad9429e52 ("tree-wide: make socket SOCK_CLOEXEC")
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
src/lxc/cmd/lxc_monitord.c
src/lxc/commands.c

index a194fbea80d8a83dea1da2caa9008ea726e725dd..5fe806131c2361f88405d2582d9edff3694cb83b 100644 (file)
@@ -159,17 +159,12 @@ static int lxc_monitord_sock_accept(int fd, uint32_t events, void *data,
        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;
index 07be1d53539a97373c00749af81277958e4a5bed..a9c2909692595b3cf3b06dbb5ddf7756a6f2fc42 100644 (file)
@@ -2080,14 +2080,10 @@ static int lxc_cmd_accept(int fd, uint32_t events, void *data,
        __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");
@@ -2122,10 +2118,6 @@ int lxc_server_init(const char *name, const char *lxcpath, const char *suffix)
                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]);
 }