]> git.proxmox.com Git - mirror_lxc.git/commitdiff
merge lxc_restart() and lxc_start()
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)
now that we have specific operations and specific arguments for each
sequence, lxc_restart() and lxc_start() can easily be merged under
a common subroutine.

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 71c103141e65d63c56d4913de9abeaf705cc0859..c79cf708dda948af224a7ec40ca2f6c5574632b9 100644 (file)
@@ -560,57 +560,24 @@ out_abort:
        return -1;
 }
 
-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);
-       SYSERROR("failed to exec %s", arg->argv[0]);
-       return 0;
-}
-
-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;
-}
-
-static struct lxc_operations start_ops = {
-       .start = start,
-       .post_start = post_start
-};
-
-int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf)
+int __lxc_start(const char *name, struct lxc_conf *conf,
+               struct lxc_operations* ops, void *data)
 {
        struct lxc_handler *handler;
        int err = -1;
        int status;
-       struct start_arg start_arg = {
-               .argv = argv,
-       };
-
-       if (lxc_check_inherited(-1))
-               return -1;
 
        handler = lxc_init(name, conf);
        if (!handler) {
                ERROR("failed to initialize the container");
                return -1;
        }
-       handler->ops = &start_ops;
-       handler->data = &start_arg;
+       handler->ops = ops;
+       handler->data = data;
 
        err = lxc_spawn(handler);
        if (err) {
-               ERROR("failed to spawn '%s'", argv[0]);
+               ERROR("failed to spawn '%s'", name);
                goto out_fini;
        }
 
@@ -639,3 +606,43 @@ out_abort:
        lxc_abort(name, handler);
        goto out_fini;
 }
+
+struct start_args {
+       char *const *argv;
+};
+
+static int start(struct lxc_handler *handler, void* data)
+{
+       struct start_args *arg = data;
+
+       NOTICE("exec'ing '%s'", arg->argv[0]);
+
+       execvp(arg->argv[0], arg->argv);
+       SYSERROR("failed to exec %s", arg->argv[0]);
+       return 0;
+}
+
+static int post_start(struct lxc_handler *handler, void* data)
+{
+       struct start_args *arg = data;
+
+       NOTICE("'%s' started with pid '%d'", arg->argv[0], handler->pid);
+       return 0;
+}
+
+static struct lxc_operations start_ops = {
+       .start = start,
+       .post_start = post_start
+};
+
+int lxc_start(const char *name, char *const argv[], struct lxc_conf *conf)
+{
+       struct start_args start_arg = {
+               .argv = argv,
+       };
+
+       if (lxc_check_inherited(-1))
+               return -1;
+
+       return __lxc_start(name, conf, &start_ops, &start_arg);
+}
index a861df13bcd63abc047dc086d833c63131a79efd..ff35bca52de410c9206b516ea256b4076b927030 100644 (file)
@@ -28,7 +28,6 @@
 
 struct lxc_conf;
 
-struct start_arg;
 struct lxc_handler;
 
 struct lxc_operations {
@@ -59,6 +58,8 @@ extern void lxc_abort(const char *name, struct lxc_handler *handler);
 extern void lxc_fini(const char *name, struct lxc_handler *handler);
 extern int lxc_set_state(const char *, struct lxc_handler *, lxc_state_t);
 extern int lxc_check_inherited(int fd_to_ignore);
+int __lxc_start(const char *, struct lxc_conf *, struct lxc_operations *,
+               void *);
 
 #endif