From 111ed96e9c6d577cb0e326811c03ecdc8cae6a69 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 21 May 2021 10:12:29 +0200 Subject: [PATCH] conf: move file descriptor synchronization with parent into single function Signed-off-by: Christian Brauner --- src/lxc/conf.c | 30 ++++++++++++++++++++++++++++-- src/lxc/conf.h | 3 +-- src/lxc/start.c | 24 ++---------------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 0fc9ddd3c..147ea9000 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1184,7 +1184,7 @@ on_error: return -1; } -int lxc_send_ttys_to_parent(struct lxc_handler *handler) +static int lxc_send_ttys_to_parent(struct lxc_handler *handler) { int ret = -1; @@ -1750,7 +1750,7 @@ static int lxc_setup_devpts_child(struct lxc_handler *handler) return 0; } -int lxc_send_devpts_to_parent(struct lxc_handler *handler) +static int lxc_send_devpts_to_parent(struct lxc_handler *handler) { int ret; @@ -4078,6 +4078,32 @@ int lxc_sync_fds_parent(struct lxc_handler *handler) return 0; } +int lxc_sync_fds_child(struct lxc_handler *handler) +{ + int ret; + + ret = lxc_seccomp_send_notifier_fd(&handler->conf->seccomp, handler->data_sock[0]); + if (ret < 0) + return syserror_ret(ret, "Failed to send seccomp notify fd to parent"); + + ret = lxc_send_devpts_to_parent(handler); + if (ret < 0) + return syserror_ret(ret, "Failed to send seccomp devpts fd to parent"); + + ret = lxc_send_ttys_to_parent(handler); + if (ret < 0) + return syserror_ret(ret, "Failed to send tty file descriptors to parent"); + + if (handler->ns_clone_flags & CLONE_NEWNET) { + ret = lxc_network_send_name_and_ifindex_to_parent(handler); + if (ret < 0) + return syserror_ret(ret, "Failed to send network device names and ifindices to parent"); + } + + TRACE("Finished syncing file descriptors with parent"); + return 0; +} + int lxc_setup(struct lxc_handler *handler) { int ret; diff --git a/src/lxc/conf.h b/src/lxc/conf.h index 8702fdcfe..57d3b4531 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -517,8 +517,6 @@ __hidden extern int lxc_idmapped_mounts_parent(struct lxc_handler *handler); __hidden extern int lxc_map_ids(struct lxc_list *idmap, pid_t pid); __hidden extern int lxc_create_tty(const char *name, struct lxc_conf *conf); __hidden extern void lxc_delete_tty(struct lxc_tty_info *ttys); -__hidden extern int lxc_send_ttys_to_parent(struct lxc_handler *handler); -__hidden extern int lxc_send_devpts_to_parent(struct lxc_handler *handler); __hidden extern int lxc_clear_config_caps(struct lxc_conf *c); __hidden extern int lxc_clear_config_keepcaps(struct lxc_conf *c); __hidden extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key, int version); @@ -583,6 +581,7 @@ static inline int chown_mapped_root(const char *path, const struct lxc_conf *con } __hidden extern int lxc_sync_fds_parent(struct lxc_handler *handler); +__hidden extern int lxc_sync_fds_child(struct lxc_handler *handler); static inline const char *get_rootfs_mnt(const struct lxc_rootfs *rootfs) { diff --git a/src/lxc/start.c b/src/lxc/start.c index e9ff4e266..cefcc099e 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -1330,32 +1330,12 @@ static int do_start(void *data) if (!lxc_sync_barrier_parent(handler, START_SYNC_CGROUP_LIMITS)) goto out_warn_father; - ret = lxc_seccomp_send_notifier_fd(&handler->conf->seccomp, data_sock0); + ret = lxc_sync_fds_child(handler); if (ret < 0) { - SYSERROR("Failed to send seccomp notify fd to parent"); + SYSERROR("Failed to sync file descriptors with parent"); goto out_warn_father; } - ret = lxc_send_devpts_to_parent(handler); - if (ret < 0) { - SYSERROR("Failed to send seccomp devpts fd to parent"); - goto out_warn_father; - } - - ret = lxc_send_ttys_to_parent(handler); - if (ret < 0) { - SYSERROR("Failed to send tty file descriptors to parent"); - goto out_warn_father; - } - - if (handler->ns_clone_flags & CLONE_NEWNET) { - ret = lxc_network_send_name_and_ifindex_to_parent(handler); - if (ret < 0) { - SYSERROR("Failed to send network device names and ifindices to parent"); - goto out_warn_father; - } - } - if (!lxc_sync_wait_parent(handler, START_SYNC_READY_START)) goto out_warn_father; -- 2.39.5