diff options
Diffstat (limited to 'src/lxc/execute.c')
-rw-r--r-- | src/lxc/execute.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/lxc/execute.c b/src/lxc/execute.c new file mode 100644 index 0000000..43210e2 --- /dev/null +++ b/src/lxc/execute.c @@ -0,0 +1,90 @@ +/* + * lxc: linux Container library + * + * (C) Copyright IBM Corp. 2007, 2008 + * + * Authors: + * Daniel Lezcano <dlezcano at fr.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> + +#include "log.h" +#include "start.h" + +lxc_log_define(lxc_execute, lxc_start); + +struct execute_args { + char *const *argv; + int quiet; +}; + +static int execute_start(struct lxc_handler *handler, void* data) +{ + int j, i = 0; + struct execute_args *my_args = data; + char **argv; + int argc = 0; + + while (my_args->argv[argc++]); + + argv = malloc((argc + my_args->quiet ? 5 : 4) * sizeof(*argv)); + if (!argv) + return 1; + + argv[i++] = LXCINITDIR "/lxc-init"; + if (my_args->quiet) + argv[i++] = "--quiet"; + argv[i++] = "--"; + for (j = 0; j < argc; j++) + argv[i++] = my_args->argv[j]; + argv[i++] = NULL; + + NOTICE("exec'ing '%s'", my_args->argv[0]); + + execvp(argv[0], argv); + SYSERROR("failed to exec %s", argv[0]); + return 1; +} + +static int execute_post_start(struct lxc_handler *handler, void* data) +{ + struct execute_args *my_args = data; + NOTICE("'%s' started with pid '%d'", my_args->argv[0], handler->pid); + return 0; +} + +static struct lxc_operations execute_start_ops = { + .start = execute_start, + .post_start = execute_post_start +}; + +int lxc_execute(const char *name, char *const argv[], int quiet, + struct lxc_conf *conf) +{ + struct execute_args args = { + .argv = argv, + .quiet = quiet + }; + + if (lxc_check_inherited(-1)) + return -1; + + return __lxc_start(name, conf, &execute_start_ops, &args); +} |