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: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
Cedric Le Goater 2010-05-26 16:54:48 +02:00 committed by Daniel Lezcano
parent 23c53af96d
commit ee70bf78e3
2 changed files with 47 additions and 39 deletions

View 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);
}

View 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