createtest.c revision 787c3ebec62eae66ad0441710ee46c8d355bfcfd
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/* liblxcapi
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Copyright © 2012 Canonical Ltd.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * This program is free software; you can redistribute it and/or modify
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * it under the terms of the GNU General Public License version 2, as
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * published by the Free Software Foundation.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * This program is distributed in the hope that it will be useful,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * but WITHOUT ANY WARRANTY; without even the implied warranty of
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * GNU General Public License for more details.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * You should have received a copy of the GNU General Public License along
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * with this program; if not, write to the Free Software Foundation, Inc.,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <lxc/lxccontainer.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <unistd.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <signal.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <stdio.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <sys/types.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <sys/wait.h>
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk#include <stdlib.h>
#include <errno.h>
#define MYNAME "lxctest1"
int main(int argc, char *argv[])
{
struct lxc_container *c;
int ret = 1;
if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
ret = 1;
goto out;
}
if (c->is_defined(c)) {
fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
goto out;
}
if (!c->set_config_item(c, "lxc.network.type", "veth")) {
fprintf(stderr, "%d: failed to set network type\n", __LINE__);
goto out;
}
c->set_config_item(c, "lxc.network.link", "lxcbr0");
c->set_config_item(c, "lxc.network.flags", "up");
if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) {
fprintf(stderr, "%d: failed to create a trusty container\n", __LINE__);
goto out;
}
if (!c->is_defined(c)) {
fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME);
goto out;
}
c->clear_config(c);
c->load_config(c, NULL);
c->want_daemonize(c, true);
if (!c->startl(c, 0, NULL)) {
fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
goto out;
}
if (!c->stop(c)) {
fprintf(stderr, "%d: failed to stop %s\n", __LINE__, MYNAME);
goto out;
}
if (!c->destroy(c)) {
fprintf(stderr, "%d: error deleting %s\n", __LINE__, MYNAME);
goto out;
}
if (c->is_defined(c)) {
fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
goto out;
}
fprintf(stderr, "all lxc_container tests passed for %s\n", c->name);
ret = 0;
out:
lxc_container_put(c);
exit(ret);
}