]> git.proxmox.com Git - mirror_lxc.git/commitdiff
fix network devices cleanup on error
authorDaniel Lezcano <daniel.lezcano@free.fr>
Thu, 25 Feb 2010 09:24:13 +0000 (10:24 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 25 Feb 2010 09:24:13 +0000 (10:24 +0100)
Delete the network devices when an error occurs before they are moved
to the network namespace (network namespace destruction triggers the
network devices deletion). Otherwise they stay in the system.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/start.c

index 5960a4c41ae06e9b9fcf40a41af5dc9b7c97abdb..26ddd03b36ab3789ada36d411e98ff5232382887 100644 (file)
@@ -1279,6 +1279,18 @@ int lxc_create_network(struct lxc_list *network)
        return 0;
 }
 
+void lxc_delete_network(struct lxc_list *network)
+{
+       struct lxc_list *iterator;
+       struct lxc_netdev *netdev;
+
+       lxc_list_for_each(iterator, network) {
+               netdev = iterator->elem;
+               if (netdev->ifindex > 0)
+                       lxc_device_delete_index(netdev->ifindex);
+       }
+}
+
 int lxc_assign_network(struct lxc_list *network, pid_t pid)
 {
        struct lxc_list *iterator;
index eede2b0869a9c8bfa1b6d8ddb24a6a748f9670c3..822149a432041b88915d0dcb853ac392eb23ce84 100644 (file)
@@ -197,6 +197,7 @@ struct lxc_conf {
 extern struct lxc_conf *lxc_conf_init(void);
 
 extern int lxc_create_network(struct lxc_list *networks);
+extern void lxc_delete_network(struct lxc_list *networks);
 extern int lxc_assign_network(struct lxc_list *networks, pid_t pid);
 
 extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
index 395a671371aa6e52f33709a4eeb8ed58d4d5e5af..dcd587b82d01df2b5169455073c6ed6e0068df2d 100644 (file)
@@ -367,7 +367,7 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[])
        handler->pid = lxc_clone(do_start, &start_arg, clone_flags);
        if (handler->pid < 0) {
                SYSERROR("failed to fork into a new namespace");
-               goto out_close;
+               goto out_delete_net;
        }
 
        close(sv[0]);
@@ -375,17 +375,17 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[])
        /* Wait for the child to be ready */
        if (read(sv[1], &sync, sizeof(sync)) < 0) {
                SYSERROR("failed to read the socket");
-               goto out_abort;
+               goto out_delete_net;
        }
 
        if (lxc_rename_nsgroup(name, handler))
-               goto out_abort;
+               goto out_delete_net;
 
        /* Create the network configuration */
        if (clone_flags & CLONE_NEWNET) {
                if (lxc_assign_network(&handler->conf->network, handler->pid)) {
                        ERROR("failed to create the configured network");
-                       goto out_abort;
+                       goto out_delete_net;
                }
        }
 
@@ -416,6 +416,9 @@ out_close:
        close(sv[1]);
        return err;
 
+out_delete_net:
+       if (clone_flags & CLONE_NEWNET)
+               lxc_delete_network(&handler->conf->network);
 out_abort:
        lxc_abort(name, handler);
        close(sv[1]);