saveconfig.c revision 787c3ebec62eae66ad0441710ee46c8d355bfcfd
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync/* liblxcapi
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync * Copyright © 2012 Canonical Ltd.
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync * This program is free software; you can redistribute it and/or modify
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync * it under the terms of the GNU General Public License version 2, as
10cdf5733351fdcd857d439ca32189e812f18682vboxsync * published by the Free Software Foundation.
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync * This program is distributed in the hope that it will be useful,
9019681d4e9b8399b951793a9dd92b63c195e0eevboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
a74782eac5771b0de57834e8c8c0247c55e8dd57vboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a74782eac5771b0de57834e8c8c0247c55e8dd57vboxsync * GNU General Public License for more details.
a74782eac5771b0de57834e8c8c0247c55e8dd57vboxsync * You should have received a copy of the GNU General Public License along
a74782eac5771b0de57834e8c8c0247c55e8dd57vboxsync * with this program; if not, write to the Free Software Foundation, Inc.,
a74782eac5771b0de57834e8c8c0247c55e8dd57vboxsync * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsyncstatic int create_container(void)
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync if (pid == 0) {
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync ret = execlp("lxc-create", "lxc-create", "-t", "busybox", "-n", MYNAME, NULL);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync // Should not return
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: lxc-create exited abnormally\n", __LINE__);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync if ((c = lxc_container_new(MYNAME, NULL)) == NULL) {
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: error opening lxc_container %s\n", __LINE__, MYNAME);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: failed to create a container\n", __LINE__);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync if (!c->is_defined(c)) {
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: %s thought it was not defined\n", __LINE__, MYNAME);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: failed writing config file /tmp/lxctest1\n", __LINE__);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync rename(LXCPATH "/" MYNAME "/config", LXCPATH "/" MYNAME "/config.bak");
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: failed writing config file\n", __LINE__);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync if (!c->destroy(c)) {
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: error deleting %s\n", __LINE__, MYNAME);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "%d: %s thought it was defined\n", __LINE__, MYNAME);
db3dbd0ed7eb69f804a8921fa23a1267ea01f46evboxsync fprintf(stderr, "all lxc_container tests passed for %s\n", c->name);