argv[i] = strdupa(luaL_checkstring(L, i+3));
argv[i] = NULL;
- lua_pushboolean(L, !!c->create(c, template_name, NULL, NULL, argv));
+ lua_pushboolean(L, !!c->create(c, template_name, NULL, NULL, 0, argv));
return 1;
}
{
struct lxc_container *c;
struct bdev_specs spec;
+ int flags = 0;
/* this is a short term test. We'll probably want to check for
* write access to lxcpath instead */
if (strcmp(my_args.bdevtype, "_unset") == 0)
my_args.bdevtype = NULL;
- if (!c->create(c, my_args.template, my_args.bdevtype, &spec, &argv[optind])) {
+ if (my_args.quiet)
+ flags = LXC_CREATE_QUIET;
+ if (!c->create(c, my_args.template, my_args.bdevtype, &spec, flags, &argv[optind])) {
ERROR("Error creating container %s", c->name);
lxc_container_put(c);
exit(1);
return p;
}
-static bool create_run_template(struct lxc_container *c, char *tpath,
+static bool create_run_template(struct lxc_container *c, char *tpath, bool quiet,
char *const argv[])
{
pid_t pid;
int ret, len, nargs = 0;
char **newargv;
+ if (quiet) {
+ close(0);
+ close(1);
+ close(2);
+ open("/dev/zero", O_RDONLY);
+ open("/dev/null", O_RDWR);
+ open("/dev/null", O_RDWR);
+ }
if (unshare(CLONE_NEWNS) < 0) {
ERROR("error unsharing mounts");
exit(1);
* arguments, you can just pass NULL.
*/
static bool lxcapi_create(struct lxc_container *c, const char *t,
- const char *bdevtype, struct bdev_specs *specs,
+ const char *bdevtype, struct bdev_specs *specs, int flags,
char *const argv[])
{
bool bret = false;
if (!load_config_locked(c, c->configfile))
goto out;
- if (!create_run_template(c, tpath, argv))
+ if (!create_run_template(c, tpath, !!(flags & LXC_CREATE_QUIET), argv))
goto out_unlock;
// now clear out the lxc_conf we have, reload from the created
}
static bool lxcapi_createl(struct lxc_container *c, const char *t,
- const char *bdevtype, struct bdev_specs *specs, ...)
+ const char *bdevtype, struct bdev_specs *specs, int flags, ...)
{
bool bret = false;
char **args = NULL, **temp;
* since we're going to wait for create to finish, I don't think we
* need to get a copy of the arguments.
*/
- va_start(ap, specs);
+ va_start(ap, flags);
while (1) {
char *arg;
arg = va_arg(ap, char *);
if (args)
args[nargs] = NULL;
- bret = c->create(c, t, bdevtype, specs, args);
+ bret = c->create(c, t, bdevtype, specs, flags, args);
out:
if (args)
#define LXC_CLONE_SNAPSHOT (1 << 3)
#define LXC_CLONE_MAXFLAGS (1 << 4)
+#define LXC_CREATE_QUIET (1 << 0)
+#define LXC_CREATE_MAXFLAGS (1 << 1)
+
struct bdev_specs;
struct lxc_container {
bool (*destroy)(struct lxc_container *c);
bool (*save_config)(struct lxc_container *c, const char *alt_file);
bool (*create)(struct lxc_container *c, const char *t, const char *bdevtype,
- struct bdev_specs *specs, char *const argv[]);
+ struct bdev_specs *specs, int flags, char *const argv[]);
bool (*createl)(struct lxc_container *c, const char *t, const char *bdevtype,
- struct bdev_specs *specs, ...);
+ struct bdev_specs *specs, int flags, ...);
/* send SIGINT to ask container to reboot */
bool (*reboot)(struct lxc_container *c);
/* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */
}
}
- if (self->container->create(self->container, template_name, NULL, NULL, create_args))
+ if (self->container->create(self->container, template_name, NULL, NULL, 0, create_args))
retval = Py_True;
else
retval = Py_False;
c = lxc_container_new(name, lxcpath);
}
c->set_config_item(c, "lxc.network.type", "empty");
- if (!c->createl(c, template, NULL, NULL, NULL)) {
+ if (!c->createl(c, template, NULL, NULL, 0, NULL)) {
TSTERR("creating container %s", name);
goto out2;
}
goto out;
}
c->save_config(c, NULL);
- if (!c->createl(c, "ubuntu", NULL, NULL, NULL)) {
+ if (!c->createl(c, "ubuntu", NULL, NULL, 0, NULL)) {
fprintf(stderr, "%d: failed to create a container\n", __LINE__);
goto out;
}
c->destroy(c);
c = lxc_container_new(name, lxcpath);
}
- if (!c->createl(c, template, NULL, NULL, NULL)) {
+ if (!c->createl(c, template, NULL, NULL, 0, NULL)) {
TSTERR("creating container %s", name);
goto out2;
}
}
c->set_config_item(c, "lxc.network.link", "lxcbr0");
c->set_config_item(c, "lxc.network.flags", "up");
- if (!c->createl(c, "ubuntu", NULL, NULL, "-r", "lucid", NULL)) {
+ if (!c->createl(c, "ubuntu", NULL, NULL, 0, "-r", "lucid", NULL)) {
fprintf(stderr, "%d: failed to create a lucid container\n", __LINE__);
goto out;
}
ret = 1;
goto out;
}
- if (!c->createl(c, "ubuntu", NULL, NULL, "-r", "lucid", NULL)) {
+ if (!c->createl(c, "ubuntu", NULL, NULL, 0, "-r", "lucid", NULL)) {
fprintf(stderr, "%d: failed to create a lucid container\n", __LINE__);
ret = 1;
goto out;
}
c->set_config_item(c, "lxc.network.link", "lxcbr0");
c->set_config_item(c, "lxc.network.flags", "up");
- if (!c->createl(c, "ubuntu", NULL, NULL, "-r", "lucid", NULL)) {
+ if (!c->createl(c, "ubuntu", NULL, NULL, 0, "-r", "lucid", NULL)) {
fprintf(stderr, "%d: failed to create a lucid container\n", __LINE__);
goto out;
}