shutdowntest.c revision 1897e3bcd36af9f3fe6d3649910a9adb93e5e988
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen/* liblxcapi
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen *
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * Copyright © 2012 Canonical Ltd.
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen *
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * This program is free software; you can redistribute it and/or modify
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * it under the terms of the GNU General Public License version 2, as
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * published by the Free Software Foundation.
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen *
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * This program is distributed in the hope that it will be useful,
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * GNU General Public License for more details.
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen *
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * You should have received a copy of the GNU General Public License along
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * with this program; if not, write to the Free Software Foundation, Inc.,
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen */
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen#include "../lxc/lxccontainer.h"
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen#include <unistd.h>
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen#include <signal.h>
f052a448696b1246ee9fc36b7c727237aed56058Timo Sirainen#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#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, "ubuntu", NULL, NULL, "-r", "lucid", NULL)) {
fprintf(stderr, "%d: failed to create a lucid 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->load_config(c, NULL);
c->want_daemonize(c);
if (!c->startl(c, 0, NULL)) {
fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
goto out;
}
fprintf(stderr, "%d: %s started, you have 60 seconds to test a console\n", __LINE__, MYNAME);
sleep(60); // wait a minute to let user connect to console
if (!c->shutdown(c, 60)) {
fprintf(stderr, "%d: failed to shut down %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);
}