Skip to content

Commit

Permalink
commands: introduce rsp_many_fds()
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 Feb 26, 2021
1 parent 49fbd9f commit 089f3f3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/lxc/commands.c
Expand Up @@ -250,6 +250,18 @@ static inline int rsp_one_fd(int fd, int fd_send, struct lxc_cmd_rsp *rsp)
return LXC_CMD_REAP_CLIENT_FD;
}

static inline int rsp_many_fds(int fd, struct unix_fds *fds, struct lxc_cmd_rsp *rsp)
{
int ret;

ret = lxc_abstract_unix_send_fds(fd, fds->fd, fds->fd_count_max,
rsp, sizeof(*rsp));
if (ret < 0)
return ret;

return LXC_CMD_REAP_CLIENT_FD;
}

static int lxc_cmd_send(const char *name, struct lxc_cmd_rr *cmd,
const char *lxcpath, const char *hashed_sock_name)
{
Expand Down Expand Up @@ -545,6 +557,44 @@ static int lxc_cmd_get_seccomp_notify_fd_callback(int fd, struct lxc_cmd_req *re
#endif
}

int lxc_cmd_get_cgroup_fd(const char *name, const char *lxcpath,
const char *controller, bool batch,
struct unix_fds *ret_fds)
{
int ret, stopped;
struct lxc_cmd_rr cmd = {
.req = {
.cmd = LXC_CMD_GET_CGROUP_FD,
},
};

if (batch && !is_empty_string(controller))
return ret_errno(EINVAL);

ret = lxc_cmd(name, &cmd, &stopped, lxcpath, NULL);
if (ret < 0)
return log_debug_errno(-1, errno, "Failed to process cgroup fd command");

if (cmd.rsp.ret < 0)
return log_debug_errno(-EBADF, errno, "Failed to receive cgroup fds");

return 0;
}

static int lxc_cmd_get_cgroup_fd_callback(int fd, struct lxc_cmd_req *req,
struct lxc_handler *handler,
struct lxc_epoll_descr *descr)
{
struct cgroup_ops *cgroup_ops = handler->cgroup_ops;
struct lxc_cmd_rsp rsp = {};
struct unix_fds fds = {};

fds.fd_count_max = cgroup_fds(cgroup_ops, fds.fd);
if (fds.fd_count_max == 0)
rsp.ret = -ENOENT;
return rsp_many_fds(fd, &fds, &rsp);
}

/*
* lxc_cmd_get_clone_flags: Get clone flags container was spawned with
*
Expand Down

0 comments on commit 089f3f3

Please sign in to comment.