]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: move file descriptor synchronization with parent into single function
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 21 May 2021 08:12:29 +0000 (10:12 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 21 May 2021 15:27:58 +0000 (17:27 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/start.c

index 0fc9ddd3cd846837b4f939320944c9c77560ebb7..147ea9000b14765114f847f98eee26ddd66d0927 100644 (file)
@@ -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;
index 8702fdcfe41d9203ea818dc6e4d6868e0acca5ba..57d3b453134f2dedc50a640a9e0957fd28f997c1 100644 (file)
@@ -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)
 {
index e9ff4e26673614489ae70ab1d1014f1e28813049..cefcc099e4799276115f4c95ca7f25d8690c3cee 100644 (file)
@@ -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;