]>
Commit | Line | Data |
---|---|---|
72d0e1cb SG |
1 | /* liblxcapi |
2 | * | |
3 | * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>. | |
4 | * Copyright © 2012 Canonical Ltd. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2, as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; if not, write to the Free Software Foundation, Inc., | |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | */ | |
e49c56d6 CB |
19 | |
20 | #include "config.h" | |
21 | ||
948955a2 | 22 | #include <lxc/lxccontainer.h> |
72d0e1cb SG |
23 | |
24 | #include <unistd.h> | |
25 | #include <signal.h> | |
26 | #include <stdio.h> | |
27 | #include <sys/types.h> | |
28 | #include <sys/wait.h> | |
29 | #include <stdlib.h> | |
30 | #include <errno.h> | |
31 | ||
32 | #define MYNAME "lxctest1" | |
33 | ||
34 | int main(int argc, char *argv[]) | |
35 | { | |
36 | struct lxc_container *c; | |
37 | int ret = 1; | |
38 | ||
afeecbba | 39 | if ((c = lxc_container_new(MYNAME, NULL)) == NULL) { |
72d0e1cb SG |
40 | fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME); |
41 | ret = 1; | |
42 | goto out; | |
43 | } | |
44 | ||
45 | if (c->is_defined(c)) { | |
46 | fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME); | |
47 | goto out; | |
48 | } | |
49 | ||
7fa3f2e9 | 50 | if (!c->set_config_item(c, "lxc.net.0.type", "veth")) { |
72d0e1cb SG |
51 | fprintf(stderr, "%d: failed to set network type\n", __LINE__); |
52 | goto out; | |
53 | } | |
56aff0c4 | 54 | |
7fa3f2e9 | 55 | c->set_config_item(c, "lxc.net.0.link", "lxcbr0"); |
56 | c->set_config_item(c, "lxc.net.0.flags", "up"); | |
56aff0c4 | 57 | |
787c3ebe | 58 | if (!c->createl(c, "busybox", NULL, NULL, 0, NULL)) { |
ca25f3bf | 59 | fprintf(stderr, "%d: failed to create a container\n", __LINE__); |
72d0e1cb SG |
60 | goto out; |
61 | } | |
62 | ||
63 | if (!c->is_defined(c)) { | |
64 | fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME); | |
65 | goto out; | |
66 | } | |
67 | ||
80a873c2 | 68 | c->clear_config(c); |
72d0e1cb | 69 | c->load_config(c, NULL); |
540f932a | 70 | c->want_daemonize(c, true); |
56aff0c4 | 71 | |
72d0e1cb SG |
72 | if (!c->startl(c, 0, NULL)) { |
73 | fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME); | |
74 | goto out; | |
75 | } | |
72d0e1cb SG |
76 | |
77 | if (!c->stop(c)) { | |
78 | fprintf(stderr, "%d: failed to stop %s\n", __LINE__, MYNAME); | |
79 | goto out; | |
80 | } | |
81 | ||
82 | if (!c->destroy(c)) { | |
83 | fprintf(stderr, "%d: error deleting %s\n", __LINE__, MYNAME); | |
84 | goto out; | |
85 | } | |
86 | ||
87 | if (c->is_defined(c)) { | |
88 | fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME); | |
89 | goto out; | |
90 | } | |
91 | ||
92 | fprintf(stderr, "all lxc_container tests passed for %s\n", c->name); | |
93 | ret = 0; | |
56aff0c4 | 94 | |
72d0e1cb SG |
95 | out: |
96 | lxc_container_put(c); | |
97 | exit(ret); | |
98 | } |