Skip to content

Commit

Permalink
commands: cleanup macros lxc_cmd_accept()
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Apr 10, 2019
1 parent f6f4304 commit 9179fca
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/lxc/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ static int lxc_cmd_handler(int fd, uint32_t events, void *data,
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);
Expand All @@ -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)
Expand Down

0 comments on commit 9179fca

Please sign in to comment.