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)) {
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;
}
/* 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;
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;
}
*/
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;
}
}
/* 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)) {
goto out_abort;
}
- close(arg->sv[1]);
+ close(handler->sv[1]);
return 0;
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);
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;
}
struct lxc_handler *handler;
int err = -1;
int status;
+ struct start_arg start_arg = {
+ .argv = argv,
+ };
if (lxc_check_inherited(-1))
return -1;
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;