1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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);
}
|