]>
git.proxmox.com Git - mirror_lxc.git/blob - src/tests/saveconfig.c
3 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
4 * Copyright © 2012 Canonical Ltd.
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.
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.
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.
22 #include <lxc/lxccontainer.h>
27 #include <sys/types.h>
32 #define MYNAME "lxctest1"
34 static int create_container(void)
45 execlp("lxc-create", "lxc-create", "-t", "busybox", "-n", MYNAME
, NULL
);
50 ret
= waitpid(pid
, &status
, 0);
62 if (!WIFEXITED(status
)) { // did not exit normally
63 fprintf(stderr
, "%d: lxc-create exited abnormally\n", __LINE__
);
67 return WEXITSTATUS(status
);
70 int main(int argc
, char *argv
[])
72 struct lxc_container
*c
;
75 if ((c
= lxc_container_new(MYNAME
, NULL
)) == NULL
) {
76 fprintf(stderr
, "%d: error opening lxc_container %s\n", __LINE__
, MYNAME
);
81 if (c
->is_defined(c
)) {
82 fprintf(stderr
, "%d: %s thought it was defined\n", __LINE__
, MYNAME
);
86 if (create_container()) {
87 fprintf(stderr
, "%d: failed to create a container\n", __LINE__
);
91 if (!c
->is_defined(c
)) {
92 fprintf(stderr
, "%d: %s thought it was not defined\n", __LINE__
, MYNAME
);
96 c
->load_config(c
, NULL
);
97 unlink("/tmp/lxctest1");
98 if (!c
->save_config(c
, "/tmp/lxctest1")) {
99 fprintf(stderr
, "%d: failed writing config file /tmp/lxctest1\n", __LINE__
);
103 rename(LXCPATH
"/" MYNAME
"/config", LXCPATH
"/" MYNAME
"/config.bak");
104 if (!c
->save_config(c
, NULL
)) {
105 fprintf(stderr
, "%d: failed writing config file\n", __LINE__
);
109 if (!c
->destroy(c
)) {
110 fprintf(stderr
, "%d: error deleting %s\n", __LINE__
, MYNAME
);
114 if (c
->is_defined(c
)) {
115 fprintf(stderr
, "%d: %s thought it was defined\n", __LINE__
, MYNAME
);
119 fprintf(stderr
, "all lxc_container tests passed for %s\n", c
->name
);
123 lxc_container_put(c
);