]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
commands: cleanup macros lxc_cmd_accept()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 17 Feb 2019 13:42:51 +0000 (14:42 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 18 Feb 2019 14:24:13 +0000 (15:24 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/commands.c

index a1f88e14fbbfe42faf94ed58ef0b4ff1d2c2de32..779213d3434a84bd098f4f2fd72274bf4a816e9c 100644 (file)
@@ -1157,7 +1157,7 @@ out_close:
 static int lxc_cmd_accept(int fd, uint32_t events, void *data,
                          struct lxc_epoll_descr *descr)
 {
-       int connection;
+       __do_close_prot_errno int connection = -EBADF;
        int opt = 1, ret = -1;
 
        connection = accept(fd, NULL, 0);
@@ -1169,27 +1169,23 @@ static int lxc_cmd_accept(int fd, uint32_t events, void *data,
        ret = fcntl(connection, F_SETFD, FD_CLOEXEC);
        if (ret < 0) {
                SYSERROR("Failed to set close-on-exec on incoming command connection");
-               goto out_close;
+               return ret;
        }
 
        ret = setsockopt(connection, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt));
        if (ret < 0) {
                SYSERROR("Failed to enable necessary credentials on command socket");
-               goto out_close;
+               return ret;
        }
 
        ret = lxc_mainloop_add_handler(descr, connection, lxc_cmd_handler, data);
        if (ret) {
                ERROR("Failed to add command handler");
-               goto out_close;
+               return ret;
        }
 
-out:
+       steal_fd(connection);
        return ret;
-
-out_close:
-       close(connection);
-       goto out;
 }
 
 int lxc_cmd_init(const char *name, const char *lxcpath, const char *suffix)