]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
replace common start_arg by private start_arg
authorCedric Le Goater <clg@vnet.ibm.com>
Wed, 26 May 2010 14:54:48 +0000 (16:54 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Wed, 26 May 2010 14:54:48 +0000 (16:54 +0200)
the following patch moves the start argument in private
structs which are opaque to lxc_spawn(). To achieve this goal,
we need to move the sv[2] socketpair and lxc_handler

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

index f589a06497d07678d56f0be0db02a9f4b6b81534..71c103141e65d63c56d4913de9abeaf705cc0859 100644 (file)
@@ -413,8 +413,7 @@ void lxc_abort(const char *name, struct lxc_handler *handler)
 
 static int do_start(void *data)
 {
-       struct start_arg *arg = data;
-       struct lxc_handler *handler = arg->handler;
+       struct lxc_handler *handler = data;
        int err = -1, sync;
 
        if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) {
@@ -422,19 +421,19 @@ static int do_start(void *data)
                return -1;
        }
 
-       close(arg->sv[1]);
+       close(handler->sv[1]);
 
        /* Be sure we don't inherit this after the exec */
-       fcntl(arg->sv[0], F_SETFD, FD_CLOEXEC);
+       fcntl(handler->sv[0], F_SETFD, FD_CLOEXEC);
 
        /* Tell our father he can begin to configure the container */
-       if (write(arg->sv[0], &sync, sizeof(sync)) < 0) {
+       if (write(handler->sv[0], &sync, sizeof(sync)) < 0) {
                SYSERROR("failed to write socket");
                return -1;
        }
 
        /* Wait for the father to finish the configuration */
-       if (read(arg->sv[0], &sync, sizeof(sync)) < 0) {
+       if (read(handler->sv[0], &sync, sizeof(sync)) < 0) {
                SYSERROR("failed to read socket");
                return -1;
        }
@@ -459,17 +458,17 @@ static int do_start(void *data)
 
        /* after this call, we are in error because this
         * ops should not return as it execs */
-       if (handler->ops->start(handler, arg))
+       if (handler->ops->start(handler, handler->data))
                return -1;
 
 out_warn_father:
        /* If the exec fails, tell that to our father */
-       if (write(arg->sv[0], &err, sizeof(err)) < 0)
+       if (write(handler->sv[0], &err, sizeof(err)) < 0)
                SYSERROR("failed to write the socket");
        return -1;
 }
 
-int lxc_spawn(struct lxc_handler *handler, struct start_arg *arg, int flags)
+int lxc_spawn(struct lxc_handler *handler)
 {
        int clone_flags;
        int sync;
@@ -477,7 +476,7 @@ int lxc_spawn(struct lxc_handler *handler, struct start_arg *arg, int flags)
        const char *name = handler->name;
 
        /* Synchro socketpair */
-       if (socketpair(AF_LOCAL, SOCK_STREAM, 0, arg->sv)) {
+       if (socketpair(AF_LOCAL, SOCK_STREAM, 0, handler->sv)) {
                SYSERROR("failed to create communication socketpair");
                return -1;
        }
@@ -492,25 +491,24 @@ int lxc_spawn(struct lxc_handler *handler, struct start_arg *arg, int flags)
                 */
                if (lxc_create_network(&handler->conf->network)) {
                        ERROR("failed to create the network");
-                       close(arg->sv[0]);
-                       close(arg->sv[1]);
+                       close(handler->sv[0]);
+                       close(handler->sv[1]);
                        return -1;
                }
        }
 
 
        /* Create a process in a new set of namespaces */
-       arg->handler = handler;
-       handler->pid = lxc_clone(do_start, arg, clone_flags);
+       handler->pid = lxc_clone(do_start, handler, clone_flags);
        if (handler->pid < 0) {
                SYSERROR("failed to fork into a new namespace");
                goto out_delete_net;
        }
 
-       close(arg->sv[0]);
+       close(handler->sv[0]);
        
        /* Wait for the child to be ready */
-       if (read(arg->sv[1], &sync, sizeof(sync)) <= 0) {
+       if (read(handler->sv[1], &sync, sizeof(sync)) <= 0) {
                ERROR("sync read failure : %m");
                failed_before_rename = 1;
        }
@@ -530,18 +528,18 @@ int lxc_spawn(struct lxc_handler *handler, struct start_arg *arg, int flags)
        }
 
        /* Tell the child to continue its initialization */
-       if (write(arg->sv[1], &sync, sizeof(sync)) < 0) {
+       if (write(handler->sv[1], &sync, sizeof(sync)) < 0) {
                SYSERROR("failed to write the socket");
                goto out_abort;
        }
 
        /* Wait for the child to exec or returning an error */
-       if (read(arg->sv[1], &sync, sizeof(sync)) < 0) {
+       if (read(handler->sv[1], &sync, sizeof(sync)) < 0) {
                ERROR("failed to read the socket");
                goto out_abort;
        }
 
-       if (handler->ops->post_start(handler, arg, flags))
+       if (handler->ops->post_start(handler, handler->data))
                goto out_abort;
 
        if (lxc_set_state(name, handler, RUNNING)) {
@@ -550,7 +548,7 @@ int lxc_spawn(struct lxc_handler *handler, struct start_arg *arg, int flags)
                goto out_abort;
        }
 
-       close(arg->sv[1]);
+       close(handler->sv[1]);
        return 0;
 
 out_delete_net:
@@ -558,12 +556,18 @@ out_delete_net:
                lxc_delete_network(&handler->conf->network);
 out_abort:
        lxc_abort(name, handler);
-       close(arg->sv[1]);
+       close(handler->sv[1]);
        return -1;
 }
 
-static int start(struct lxc_handler *handler, struct start_arg *arg)
+struct start_arg {
+       char *const *argv;
+};
+
+static int start(struct lxc_handler *handler, void* data)
 {
+       struct start_arg *arg = data;
+
        NOTICE("exec'ing '%s'", arg->argv[0]);
 
        execvp(arg->argv[0], arg->argv);
@@ -571,9 +575,10 @@ static int start(struct lxc_handler *handler, struct start_arg *arg)
        return 0;
 }
 
-static int post_start(struct lxc_handler *handler, struct start_arg *arg,
-                     int flags)
+static int post_start(struct lxc_handler *handler, void* data)
 {
+       struct start_arg *arg = data;
+
        NOTICE("'%s' started with pid '%d'", arg->argv[0], handler->pid);
        return 0;
 }
@@ -588,6 +593,9 @@ int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf)
        struct lxc_handler *handler;
        int err = -1;
        int status;
+       struct start_arg start_arg = {
+               .argv = argv,
+       };
 
        if (lxc_check_inherited(-1))
                return -1;
@@ -598,12 +606,9 @@ int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf)
                return -1;
        }
        handler->ops = &start_ops;
+       handler->data = &start_arg;
 
-       struct start_arg start_arg = {
-               .argv = argv,
-       };
-
-       err = lxc_spawn(handler, &start_arg, 0);
+       err = lxc_spawn(handler);
        if (err) {
                ERROR("failed to spawn '%s'", argv[0]);
                goto out_fini;
index ea24855af23f1b2fc946da83b5b1cd9fa105ad22..a861df13bcd63abc047dc086d833c63131a79efd 100644 (file)
@@ -32,8 +32,8 @@ struct start_arg;
 struct lxc_handler;
 
 struct lxc_operations {
-       int (*start)(struct lxc_handler *, struct start_arg *);
-       int (*post_start)(struct lxc_handler *, struct start_arg *, int);
+       int (*start)(struct lxc_handler *, void *);
+       int (*post_start)(struct lxc_handler *, void *);
 };
 
 struct lxc_handler {
@@ -45,18 +45,14 @@ struct lxc_handler {
        sigset_t oldmask;
        struct lxc_conf *conf;
        struct lxc_operations *ops;
-};
-
-struct start_arg {
-       struct lxc_handler *handler;
+       void *data;
        int sv[2];
        char *const *argv;
        int sfd;
 };
 
 extern struct lxc_handler *lxc_init(const char *name, struct lxc_conf *);
-extern int lxc_spawn(struct lxc_handler *, struct start_arg *start_arg,
-       int restart_flags);
+extern int lxc_spawn(struct lxc_handler *);
 
 extern int lxc_poll(const char *name, struct lxc_handler *handler);
 extern void lxc_abort(const char *name, struct lxc_handler *handler);