2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <sys/types.h>
35 lxc_log_define(lxc_execute
, lxc_start
);
42 static int execute_start(struct lxc_handler
*handler
, void* data
)
45 struct execute_args
*my_args
= data
;
47 int argc
= 0, argc_add
;
50 while (my_args
->argv
[argc
++]);
55 if (!handler
->conf
->rootfs
.path
) {
57 if (lxc_log_has_valid_level())
61 argv
= malloc((argc
+ argc_add
) * sizeof(*argv
));
65 initpath
= choose_init(NULL
);
67 ERROR("Failed to find an lxc-init or init.lxc");
72 argv
[i
++] = "--quiet";
73 if (!handler
->conf
->rootfs
.path
) {
75 argv
[i
++] = (char *)handler
->name
;
76 argv
[i
++] = "--lxcpath";
77 argv
[i
++] = (char *)handler
->lxcpath
;
79 if (lxc_log_has_valid_level()) {
80 argv
[i
++] = "--logpriority";
82 lxc_log_priority_to_string(lxc_log_get_level());
86 for (j
= 0; j
< argc
; j
++)
87 argv
[i
++] = my_args
->argv
[j
];
90 NOTICE("exec'ing '%s'", my_args
->argv
[0]);
92 execvp(argv
[0], argv
);
93 SYSERROR("failed to exec %s", argv
[0]);
101 static int execute_post_start(struct lxc_handler
*handler
, void* data
)
103 struct execute_args
*my_args
= data
;
104 NOTICE("'%s' started with pid '%d'", my_args
->argv
[0], handler
->pid
);
108 static struct lxc_operations execute_start_ops
= {
109 .start
= execute_start
,
110 .post_start
= execute_post_start
113 int lxc_execute(const char *name
, char *const argv
[], int quiet
,
114 struct lxc_conf
*conf
, const char *lxcpath
, bool backgrounded
)
116 struct execute_args args
= {
121 if (lxc_check_inherited(conf
, false, -1))
124 conf
->is_execute
= 1;
125 return __lxc_start(name
, conf
, &execute_start_ops
, &args
, lxcpath
, backgrounded
);