Commit ee70bf78 by Cedric Le Goater Committed by Daniel Lezcano

merge lxc_restart() and lxc_start()

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: 's avatarCedric Le Goater <clg@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 23c53af9
...@@ -560,57 +560,24 @@ out_abort: ...@@ -560,57 +560,24 @@ out_abort:
return -1; return -1;
} }
struct start_arg { int __lxc_start(const char *name, struct lxc_conf *conf,
char *const *argv; struct lxc_operations* ops, void *data)
};
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)
{ {
struct lxc_handler *handler; struct lxc_handler *handler;
int err = -1; int err = -1;
int status; int status;
struct start_arg start_arg = {
.argv = argv,
};
if (lxc_check_inherited(-1))
return -1;
handler = lxc_init(name, conf); handler = lxc_init(name, conf);
if (!handler) { if (!handler) {
ERROR("failed to initialize the container"); ERROR("failed to initialize the container");
return -1; return -1;
} }
handler->ops = &start_ops; handler->ops = ops;
handler->data = &start_arg; handler->data = data;
err = lxc_spawn(handler); err = lxc_spawn(handler);
if (err) { if (err) {
ERROR("failed to spawn '%s'", argv[0]); ERROR("failed to spawn '%s'", name);
goto out_fini; goto out_fini;
} }
...@@ -639,3 +606,43 @@ out_abort: ...@@ -639,3 +606,43 @@ out_abort:
lxc_abort(name, handler); lxc_abort(name, handler);
goto out_fini; 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);
}
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
struct lxc_conf; struct lxc_conf;
struct start_arg;
struct lxc_handler; struct lxc_handler;
struct lxc_operations { struct lxc_operations {
...@@ -59,6 +58,8 @@ extern void lxc_abort(const char *name, struct lxc_handler *handler); ...@@ -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 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_set_state(const char *, struct lxc_handler *, lxc_state_t);
extern int lxc_check_inherited(int fd_to_ignore); extern int lxc_check_inherited(int fd_to_ignore);
int __lxc_start(const char *, struct lxc_conf *, struct lxc_operations *,
void *);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment