lxccontainer.c revision 735f2c6e504a541cbb2592a3f94858bf337a24ff
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen * Copyright © 2012 Canonical Ltd.
b87761f9bbef949f31dae297e619ac3f5e9c2b2eTimo Sirainen * This library is free software; you can redistribute it and/or
b87761f9bbef949f31dae297e619ac3f5e9c2b2eTimo Sirainen * modify it under the terms of the GNU Lesser General Public
a99b64f7d63812806ee40c2e8a347343fa3b84a7Timo Sirainen * License as published by the Free Software Foundation; either
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * version 2.1 of the License, or (at your option) any later version.
0371406d952fe51367c7be91703e5634b7d9d225Timo Sirainen * This library is distributed in the hope that it will be useful,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * but WITHOUT ANY WARRANTY; without even the implied warranty of
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * Lesser General Public License for more details.
a99b64f7d63812806ee40c2e8a347343fa3b84a7Timo Sirainen * You should have received a copy of the GNU Lesser General Public
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * License along with this library; if not, write to the Free Software
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen#include <../include/ifaddrs.h>
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen#define NOT_SUPPORTED_ERROR "the requested function %s is not currently supported with unprivileged containers"
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen/* Define faccessat() if missing from the C library */
f4c0b1874b0533bcf2df1d28d584ff02cfdae3faTimo Sirainenstatic int faccessat(int __fd, const char *__file, int __type, int __flag)
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainenreturn syscall(__NR_faccessat, __fd, __file, __type, __flag);
5fbf8719b9ef072295c16bc4492f9f0ece92117dTimo Sirainenstatic bool config_file_exists(const char *lxcpath, const char *cname)
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen /* $lxcpath + '/' + $cname + '/config' + \0 */
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen int ret, len = strlen(lxcpath) + strlen(cname) + 9;
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen ret = snprintf(fname, len, "%s/%s/config", lxcpath, cname);
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen return false;
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen * A few functions to help detect when a container creation failed.
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen * If a container creation was killed partway through, then trying
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen * to actually start that container could harm the host. We detect
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen * this by creating a 'partial' file under the container directory,
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen * and keeping an advisory lock. When container creation completes,
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen * we remove that file. When we load or try to start a container, if
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen * we find that file, without a flock, we remove the container.
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainenstatic int ongoing_create(struct lxc_container *c)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen int len = strlen(c->config_path) + strlen(c->name) + 10;
407caeb5d0c8a6b158e2caef48dd909011d40340Timo Sirainen ret = snprintf(path, len, "%s/%s/partial", c->config_path, c->name);
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen // give benefit of the doubt
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (fcntl(fd, F_GETLK, &lk) == 0 && lk.l_pid != -1) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen // create is still ongoing
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen // create completed but partial is still there.
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic int create_partial(struct lxc_container *c)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen // $lxcpath + '/' + $name + '/partial' + \0
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen int len = strlen(c->config_path) + strlen(c->name) + 10;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ret = snprintf(path, len, "%s/%s/partial", c->config_path, c->name);
1d132fe27d010b73aacc605b4c6257b0079f9e97Timo Sirainen if ((fd=open(path, O_RDWR | O_CREAT | O_EXCL, 0755)) < 0) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen SYSERROR("Error locking partial file %s", path);
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainenstatic void remove_partial(struct lxc_container *c, int fd)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen // $lxcpath + '/' + $name + '/partial' + \0
d16b506f5540e3407d256bda35624b38a5ecf88fTimo Sirainen int len = strlen(c->config_path) + strlen(c->name) + 10;
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen ret = snprintf(path, len, "%s/%s/partial", c->config_path, c->name);
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen SYSERROR("Error unlink partial file %s", path);
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * 1. container_mem_lock(c) protects the struct lxc_container from multiple threads.
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * 2. container_disk_lock(c) protects the on-disk container data - in particular the
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * container configuration file.
1d132fe27d010b73aacc605b4c6257b0079f9e97Timo Sirainen * The container_disk_lock also takes the container_mem_lock.
1d132fe27d010b73aacc605b4c6257b0079f9e97Timo Sirainen * 3. thread_mutex protects process data (ex: fd table) from multiple threads.
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * NOTHING mutexes two independent programs with their own struct
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * lxc_container for the same c->name, between API calls. For instance,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * c->config_read(); c->start(); Between those calls, data on disk
a0b89f3b1df99b3a32f44623f13ad1893118825bTimo Sirainen * could change (which shouldn't bother the caller unless for instance
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * the rootfs get moved). c->config_read(); update; c->config_write();
a0b89f3b1df99b3a32f44623f13ad1893118825bTimo Sirainen * Two such updaters could race. The callers should therefore check their
a99b64f7d63812806ee40c2e8a347343fa3b84a7Timo Sirainen * results. Trying to prevent that would necessarily expose us to deadlocks
a99b64f7d63812806ee40c2e8a347343fa3b84a7Timo Sirainen * due to hung callers. So I prefer to keep the locks only within our own
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * functions, not across functions.
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * If you're going to clone while holding a lxccontainer, increment
a99b64f7d63812806ee40c2e8a347343fa3b84a7Timo Sirainen * c->numthreads (under privlock) before forking. When deleting,
a99b64f7d63812806ee40c2e8a347343fa3b84a7Timo Sirainen * decrement numthreads under privlock, then if it hits 0 you can delete.
a99b64f7d63812806ee40c2e8a347343fa3b84a7Timo Sirainen * Do not ever use a lxccontainer whose numthreads you did not bump.
5fbf8719b9ef072295c16bc4492f9f0ece92117dTimo Sirainenstatic void lxc_container_free(struct lxc_container *c)
af98c413eebe0c8c49fbe785fc34915c92ebe8c1Timo Sirainen * Consider the following case:
af98c413eebe0c8c49fbe785fc34915c92ebe8c1Timo Sirainenfreer | racing get()er
af98c413eebe0c8c49fbe785fc34915c92ebe8c1Timo Sirainen==================================================================
9349a0afffad990e45d3ad33081e1d2d9e68a753Timo Sirainenlxc_container_put() | lxc_container_get()
4c9c55e15f35474f53f11659e796c63b1c34e884Timo Sirainen\ lxclock(c->privlock) | c->numthreads < 1? (no)
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen\ c->numthreads = 0 | \ lxclock(c->privlock) -> waits
4c9c55e15f35474f53f11659e796c63b1c34e884Timo Sirainen\ lxcunlock() | \
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen\ lxc_container_free() | \ lxclock() returns
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen | \ c->numthreads < 1 -> return 0
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen\ \ (free stuff) |
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen\ \ sem_destroy(privlock) |
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * When the get()er checks numthreads the first time, one of the following
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * 1. freer has set numthreads = 0. get() returns 0
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * 2. freer is between lxclock and setting numthreads to 0. get()er will
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen * sem_wait on privlock, get lxclock after freer() drops it, then see
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen * numthreads is 0 and exit without touching lxclock again..
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen * 3. freer has not yet locked privlock. If get()er runs first, then put()er
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen * will see --numthreads = 1 and not call lxc_container_free().
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen // if someone else has already started freeing the container, don't
a94936bafd127680184da114c6a177b37ff656e5Timo Sirainen // try to take the lock, which may be invalid
22627da0fb77c1d0d9a8e8bc485ef5540b6f2e69Timo Sirainen // bail without trying to unlock, bc the privlock is now probably
3e28b527dd6048a40684afd29cff0ee008fc0014Timo Sirainen // in freed memory
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainenstatic bool lxcapi_is_defined(struct lxc_container *c)
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen bool ret = false;
c44f402f17f9a58ead24ac0083945cae86fb172bTimo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
b457d2ecf97fb52064f9dd563fd4e8065af39dfbTimo Sirainenstatic const char *lxcapi_state(struct lxc_container *c)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool is_stopped(struct lxc_container *c)
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return (s == STOPPED);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_is_running(struct lxc_container *c)
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen const char *s;
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen return false;
e20e638805c4bd54e039891a3e92760b1dfa189aTimo Sirainen return false;
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainenstatic bool lxcapi_freeze(struct lxc_container *c)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainenstatic bool lxcapi_unfreeze(struct lxc_container *c)
e958a3c4573058f17999f0083a34080ca35e34d8Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainenstatic int lxcapi_console_getfd(struct lxc_container *c, int *ttynum, int *masterfd)
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen ttyfd = lxc_console_getfd(c, ttynum, masterfd);
68f0dfb4b2815ecbc1bd8d8a68adcfd577ec55aeTimo Sirainenstatic int lxcapi_console(struct lxc_container *c, int ttynum, int stdinfd,
68f0dfb4b2815ecbc1bd8d8a68adcfd577ec55aeTimo Sirainen return lxc_console(c, ttynum, stdinfd, stdoutfd, stderrfd, escape);
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainenstatic pid_t lxcapi_init_pid(struct lxc_container *c)
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen return lxc_cmd_get_init_pid(c->name, c->config_path);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool load_config_locked(struct lxc_container *c, const char *fname)
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen return false;
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen if (lxc_config_read(fname, c->lxc_conf, false) != 0)
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_load_config(struct lxc_container *c, const char *alt_file)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * If we're reading something other than the container's config,
f6e301cb2060c4367d8145e2bf5d553ba87ceb34Timo Sirainen * we only need to lock the in-memory container. If loading the
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * container's config file, take the disk lock.
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_want_daemonize(struct lxc_container *c, bool state)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (!c || !c->lxc_conf)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen /* daemonize implies close_all_fds so set it */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (!c || !c->lxc_conf)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_wait(struct lxc_container *c, const char *state, int timeout)
24ce0c343cefe54af841871fa39dbc3464028b06Timo Sirainen return false;
24ce0c343cefe54af841871fa39dbc3464028b06Timo Sirainen ret = lxc_wait(c->name, state, timeout, c->config_path);
24ce0c343cefe54af841871fa39dbc3464028b06Timo Sirainen return ret == 0;
9fcf7b79236b0045f7709718f7b65ada516565e7Timo Sirainenstatic bool wait_on_daemonized_start(struct lxc_container *c, int pid)
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen /* we'll probably want to make this timeout configurable? */
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * our child is going to fork again, then exit. reap the
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen if (ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen DEBUG("failed waiting for first dual-fork child");
24ce0c343cefe54af841871fa39dbc3464028b06Timo Sirainenstatic bool am_single_threaded(void)
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
3656c91dcb8336814bebd4500e81c3dde25233e6Timo Sirainen * I can't decide if it'd be more convenient for callers if we accept '...',
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * or a null-terminated array (i.e. execl vs execv)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv[])
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen /* container exists */
36c4702131e5a04984ad5d07cf5d8d5c633d43c3Timo Sirainen return false;
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen /* container has been setup */
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
5fe06fea9fee0f5e4e9cb49f6866877223f78b85Timo Sirainen ERROR("Error checking for incomplete creation");
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen ERROR("Error: %s creation was not completed", c->name);
ab1b9a793d57a60c230a41f65f1a25d52c026233Timo Sirainen return false;
36c4702131e5a04984ad5d07cf5d8d5c633d43c3Timo Sirainen ERROR("Error: creation of %s is ongoing", c->name);
36c4702131e5a04984ad5d07cf5d8d5c633d43c3Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen /* is this app meant to be run through lxcinit, as in lxc-execute? */
36c4702131e5a04984ad5d07cf5d8d5c633d43c3Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen ret = lxc_execute(c->name, argv, 1, conf, c->config_path);
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return ret == 0 ? true : false;
840a3701b7a0f7fadd17738998c33790a8dfad2dTimo Sirainen * say, I'm not sure - what locks do we want here? Any?
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * Is liblxc's locking enough here to protect the on disk
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * container? We don't want to exclude things like lxc_info
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * while container is running...
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen /* Set to NULL because we don't want father unlink
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * the PID file, child will do the free and unlink.
06f537a8e0b399222cc2a7755015ef3963525fd2Timo Sirainen /* second fork to be reparented by init */
06f537a8e0b399222cc2a7755015ef3963525fd2Timo Sirainen return false;
06f537a8e0b399222cc2a7755015ef3963525fd2Timo Sirainen /* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */
06f537a8e0b399222cc2a7755015ef3963525fd2Timo Sirainen return false;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen ERROR("Cannot start non-daemonized container when threaded");
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* We need to write PID file after daeminize, so we always
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * write the right PID.
26cdaf7097427fa90343260fa236af12ab93cca3Timo Sirainen SYSERROR("Failed to create pidfile '%s' for '%s'",
26cdaf7097427fa90343260fa236af12ab93cca3Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ret = lxc_start(c->name, argv, conf, c->config_path);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return (ret == 0 ? true : false);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * note there MUST be an ending NULL
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_startl(struct lxc_container *c, int useinit, ...)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen bool bret = false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* container exists */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* pass NULL if no arguments were supplied */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen bret = lxcapi_start(c, useinit, *inargs ? inargs : NULL);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_stop(struct lxc_container *c)
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return ret == 0;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic int do_create_container_dir(const char *path, struct lxc_conf *conf)
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen SYSERROR("failed to create container path %s", path);
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen if (!lxc_list_empty(&conf->id_map) && chown_mapped_root(p, conf) != 0) {
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen * create the standard expected container dir
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainenstatic bool create_container_dir(struct lxc_container *c)
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen len = strlen(c->config_path) + strlen(c->name) + 2;
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ret = snprintf(s, len, "%s/%s", c->config_path, c->name);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return false;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen ret = do_create_container_dir(s, c->lxc_conf);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen return ret == 0;
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic const char *lxcapi_get_config_path(struct lxc_container *c);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic bool lxcapi_set_config_item(struct lxc_container *c, const char *key, const char *v);
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * do_bdev_create: thin wrapper around bdev_create(). Like bdev_create(),
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen * it returns a mounted bdev on success, NULL on error.
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenstatic struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen /* rootfs.path or lxcpath/lxcname/rootfs */
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if (c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) == 0) {
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen const char *lxcpath = lxcapi_get_config_path(c);
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen ret = snprintf(dest, len, "%s/%s/rootfs", lxcpath, c->name);
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen bdev = bdev_create(dest, type, c->name, specs);
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen ERROR("Failed to create backing store type %s", type);
9672bb2a11c37c275d695451accd824da5c9e485Timo Sirainen lxcapi_set_config_item(c, "lxc.rootfs", bdev->src);
9672bb2a11c37c275d695451accd824da5c9e485Timo Sirainen /* if we are not root, chown the rootfs dir to root in the
9672bb2a11c37c275d695451accd824da5c9e485Timo Sirainen * target uidmap */
9672bb2a11c37c275d695451accd824da5c9e485Timo Sirainen if (geteuid() != 0 || (c->lxc_conf && !lxc_list_empty(&c->lxc_conf->id_map))) {
9672bb2a11c37c275d695451accd824da5c9e485Timo Sirainen if (chown_mapped_root(bdev->dest, c->lxc_conf) < 0) {
9672bb2a11c37c275d695451accd824da5c9e485Timo Sirainen ERROR("Error chowning %s to container root", bdev->dest);
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen * Given the '-t' template option to lxc-create, figure out what to
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen * do. If the template is a full executable path, use that. If it
9c2b0eb659540b9db8dd3a8a6a2515921fbe8eebTimo Sirainen * is something like 'sshd', then return $templatepath/lxc-sshd.
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen * On success return the template, on error return NULL.
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainenstatic char *get_template_path(const char *t)
9c2b0eb659540b9db8dd3a8a6a2515921fbe8eebTimo Sirainen len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;
9c2b0eb659540b9db8dd3a8a6a2515921fbe8eebTimo Sirainen ret = snprintf(tpath, len, "%s/lxc-%s", LXCTEMPLATEDIR, t);
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainenstatic bool create_run_template(struct lxc_container *c, char *tpath, bool quiet,
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen char *const argv[])
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen SYSERROR("failed to fork task for container creation template");
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen return false;
f4c0b1874b0533bcf2df1d28d584ff02cfdae3faTimo Sirainen * for an overlay create, what the user wants is the template to fill
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * in what will become the readonly lower layer. So don't mount for
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen * the template
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen bdev = bdev_init(c->lxc_conf, src, c->lxc_conf->rootfs.mount, NULL);
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen if (geteuid() == 0) {
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen if (mount(NULL, "/", NULL, MS_SLAVE|MS_REC, NULL)) {
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen SYSERROR("Failed to make / rslave to run template");
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen if (strcmp(bdev->type, "dir") && strcmp(bdev->type, "btrfs")) {
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen if (geteuid() != 0) {
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen ERROR("non-root users can only create btrfs and directory-backed containers");
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen } else { // TODO come up with a better way here!
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * create our new array, pre-pend the template name and
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen nargs += 4; // template, path, rootfs and name args
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen len = strlen(c->config_path) + strlen(c->name) + strlen("--path=") + 2;
c93aca832ee532010ead91b85fa9f614132e1be2Stephan Bosch ret = snprintf(patharg, len, "--path=%s/%s", c->config_path, c->name);
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen len = strlen("--name=") + strlen(c->name) + 1;
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen ret = snprintf(namearg, len, "--name=%s", c->name);
a343811459d1d2259e668f369646a20f02301c2cTimo Sirainen len = strlen("--rootfs=") + 1 + strlen(bdev->dest);
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen ret = snprintf(rootfsarg, len, "--rootfs=%s", bdev->dest);
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen /* add passed-in args */
892b3cbf0eba9ba455448adcf71864a409345c6dTimo Sirainen /* add trailing NULL */
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen newargv = realloc(newargv, nargs * sizeof(*newargv));
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * If we're running the template in a mapped userns, then
6b2738c39a868ff9291867138c55029fc40cf105Timo Sirainen * we prepend the template command with:
bfdf0fd7b6186f64cbdcbf1cb2bf9c42a9007b77Timo Sirainen * lxc-usernsexec <-m map1> ... <-m mapn> --
bfdf0fd7b6186f64cbdcbf1cb2bf9c42a9007b77Timo Sirainen * and we append "--mapped-uid x", where x is the mapped uid
bfdf0fd7b6186f64cbdcbf1cb2bf9c42a9007b77Timo Sirainen * for our geteuid()
a343811459d1d2259e668f369646a20f02301c2cTimo Sirainen ret = snprintf(n2[n2args-1], 200, "%c:%lu:%lu:%lu",
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen int hostid_mapped = mapped_hostid(geteuid(), conf, ID_TYPE_UID);
9c2b0eb659540b9db8dd3a8a6a2515921fbe8eebTimo Sirainen n2 = realloc(n2, (nargs + n2args + extraargs) * sizeof(char *));
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen hostid_mapped = find_unmapped_nsuid(conf, ID_TYPE_UID);
bfdf0fd7b6186f64cbdcbf1cb2bf9c42a9007b77Timo Sirainen ret = snprintf(n2[n2args-1], 200, "u:%d:%d:1",
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen int hostgid_mapped = mapped_hostid(getegid(), conf, ID_TYPE_GID);
b87761f9bbef949f31dae297e619ac3f5e9c2b2eTimo Sirainen n2 = realloc(n2, (nargs + n2args + extraargs) * sizeof(char *));
b87761f9bbef949f31dae297e619ac3f5e9c2b2eTimo Sirainen hostgid_mapped = find_unmapped_nsuid(conf, ID_TYPE_GID);
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen ret = snprintf(n2[n2args-1], 200, "g:%d:%d:1",
0ae010139a1bb3b29fbf117c5da1a6a6c6b7b5a0Timo Sirainen for (i = 0; i < nargs; i++)
0ae010139a1bb3b29fbf117c5da1a6a6c6b7b5a0Timo Sirainen // Finally add "--mapped-uid $uid" to tell template what to chown
0ae010139a1bb3b29fbf117c5da1a6a6c6b7b5a0Timo Sirainen // cached images to
0ae010139a1bb3b29fbf117c5da1a6a6c6b7b5a0Timo Sirainen // note n2[n2args-1] is NULL
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen /* execute */
1ac19c5c2b66a12f5598792aad15114ee3eb62e2Timo Sirainen SYSERROR("failed to execute template %s", tpath);
bd63b5b860658b01b1f46f26d406e1e4a9dc019aTimo Sirainen ERROR("container creation template for %s failed", c->name);
4371df92c07fb923aabca7e90d307eccac48b2d6Timo Sirainen return false;
0371406d952fe51367c7be91703e5634b7d9d225Timo Sirainenstatic bool prepend_lxc_header(char *path, const char *t, char *const argv[])
char *tpath;
if (f == NULL)
goto out_error;
goto out_error;
goto out_error;
goto out_error;
goto out_free_contents;
f = NULL;
if (ret < 0)
goto out_free_contents;
#if HAVE_LIBGNUTLS
if (!tpath) {
goto out_free_contents;
if (ret < 0) {
goto out_free_contents;
if (f == NULL) {
if (argv) {
while (*argv) {
argv++;
#if HAVE_LIBGNUTLS
for (i=0; i<SHA_DIGEST_LENGTH; i++)
fclose(f);
ret = 0;
int newret;
if (ret == 0)
if (ret < 0) {
if (c->lxc_conf) {
char *const argv[])
bool ret = false;
int partial_fd;
if (!tpath) {
goto out;
goto free_tpath;
if (!c->lxc_conf) {
ERROR("Error loading default configuration file %s", lxc_global_config_value("lxc.default_config"));
goto free_tpath;
if (!create_container_dir(c))
goto free_tpath;
goto out;
goto out;
ret = true;
goto out;
goto out;
if (pid < 0) {
goto out_unlock;
exit(0);
goto out_unlock;
goto out_unlock;
goto out_unlock;
goto out_unlock;
if (partial_fd >= 0)
out:
if (!ret && c)
if (tpath)
return ret;
if (!c->is_running(c))
if (pid <= 0)
bool retv;
if (!c->is_running(c))
if (pid <= 0)
return retv;
bool bret = false;
if (!args) {
goto out;
out:
return bret;
int ret;
if (!c || !c->lxc_conf)
if (container_mem_lock(c))
if (!ret)
return ret == 0;
if (!c->is_running(c))
goto out;
if ((geteuid() != 0 || (c->lxc_conf && !lxc_list_empty(&c->lxc_conf->id_map))) && access("/proc/self/ns/user", F_OK) == 0) {
goto out;
if (userns < 0) {
goto out;
goto out;
goto out;
if (netns < 0) {
goto out;
goto out;
out:
if (!newnames) {
if (!newlist) {
if (sort)
qsort(newlist, pos + 1, sizeof(struct lxc_container *), (int (*)(const void *,const void *))container_cmp);
return (char **)bsearch(&cname, *names, size, sizeof(char *), (int (*)(const void *, const void *))string_cmp);
return NULL;
if (pid < 0) {
return NULL;
if (!enter_to_ns(c)) {
goto out;
goto out;
if (nbytes < 0) {
goto out;
count++;
ret = 0;
out:
if (interfaceArray)
count++;
for(i=0;i<count;i++)
if(interfaces)
return interfaces;
static char** lxcapi_get_ips(struct lxc_container *c, const char* interface, const char* family, int scope)
return NULL;
if (pid < 0) {
return NULL;
if (!enter_to_ns(c)) {
goto out;
goto out;
sizeof(addressOutputBuffer));
if (!address)
if (nbytes < 0) {
goto out;
count++;
ret = 0;
out:
if(interfaceArray)
count++;
for(i=0;i<count;i++)
if(addresses)
return addresses;
int ret;
if (!c || !c->lxc_conf)
if (container_mem_lock(c))
return ret;
char *ret;
if (!c || !c->lxc_conf)
return NULL;
if (container_mem_lock(c))
return NULL;
return ret;
if (!key)
if (!c || !c->lxc_conf)
if (container_mem_lock(c))
return ret;
int lret;
if (!alt_file)
if (!alt_file)
if (!c->lxc_conf) {
ERROR("Error loading default configuration file %s while saving %s", lxc_global_config_value("lxc.default_config"), c->name);
if (!create_container_dir(c))
need_disklock = true;
if (need_disklock)
if (lret)
if (!fout)
goto out;
ret = true;
out:
if (need_disklock)
return ret;
int ret, v = 0;
FILE *f;
bool bret = false;
if (container_disk_lock(c))
c->name);
goto out;
fclose(f);
goto out;
goto out;
fclose(f);
goto out;
if (ret != 0) {
goto out;
bret = true;
out:
return bret;
static void strip_newline(char *p)
struct lxc_container *p;
FILE *f;
int ret;
if (f == NULL)
goto out;
out:
fclose(f);
int ret, v;
FILE *f;
bool bret = false;
c->name);
goto out;
goto out;
fclose(f);
goto out;
bret = v != 0;
out:
return bret;
int count=0;
if (!dir)
if (!direntp)
count++;
return count > 0;
struct bdev *r;
int ret = 0;
bdev_put(r);
return ret;
if (setgid(0) < 0) {
if (setuid(0) < 0) {
bool bret = false;
int ret;
if (!c || !lxcapi_is_defined(c))
if (container_disk_lock(c))
if (!is_stopped(c)) {
goto out;
if (am_unpriv())
if (ret < 0) {
goto out;
mod_all_rdeps(c, false);
if (am_unpriv())
if (ret < 0) {
goto out;
bret = true;
out:
return bret;
if (!c || !lxcapi_is_defined(c))
if (has_snapshots(c)) {
if (has_fs_snapshots(c)) {
return container_destroy(c);
if (!c || !lxcapi_is_defined(c))
if (!lxcapi_snapshot_destroy_all(c)) {
return lxcapi_destroy(c);
if (!c->lxc_conf)
if (!c->lxc_conf)
if (!config)
if (container_mem_lock(c))
if (!c || !c->configfile)
return NULL;
if (!c || !c->config_path)
return NULL;
return (const char *)(c->config_path);
char *newpath;
if (!c->config_path)
if (!newpath)
if (c->configfile)
if (container_mem_lock(c))
goto err;
if (c->config_path)
c->config_path = p;
if (!set_config_filename(c)) {
err:
if (oldpath)
int ret;
if (is_stopped(c))
if (container_disk_lock(c))
return ret == 0;
static int lxcapi_get_cgroup_item(struct lxc_container *c, const char *subsys, char *retv, int inlen)
int ret;
if (is_stopped(c))
if (container_disk_lock(c))
return ret;
const char *lxc_get_version(void)
return LXC_VERSION;
if (ret < 0) {
if (in < 0) {
if (out < 0) {
if (len < 0) {
goto err;
if (len == 0)
goto err;
if (ret) {
err:
char *cpath;
for (i=0; i<NUM_LXC_HOOKS; i++) {
if (ret < 0)
FILE *f;
unsigned int seed;
fclose(f);
if (n->hwaddr)
int ret;
if (!oldpath)
int ret;
c->name);
int ret;
FILE *f;
bool bret;
c->name);
bret = true;
bret = false;
if (fclose(f) != 0)
bret = false;
return bret;
int need_rdep;
if (!bdev) {
if (need_rdep) {
mod_all_rdeps(c, true);
struct clone_update_data {
int flags;
char **hookargs;
if (setgid(0) < 0) {
if (setuid(0) < 0) {
if (!bdev)
if (detect_shared_rootfs()) {
only rootfs gets converted (copied/snapshotted) on clone.
return ret;
char **hookargs)
if (!c || !c->is_defined(c))
return NULL;
if (container_mem_lock(c))
return NULL;
if (!is_stopped(c)) {
goto out;
if (!newname)
if (!lxcpath)
goto out;
goto out;
goto out;
if (!fout) {
goto out;
goto out;
if (am_unpriv()) {
goto out;
if (!c2) {
lxcpath);
goto out;
if (ret < 0)
goto out;
goto out;
if (ret < 0) {
goto out;
goto out;
goto out;
goto out;
goto out;
if (pid > 0) {
if (ret)
goto out;
return c2;
if (am_unpriv())
&data);
if (ret < 0)
exit(0);
out:
if (c2) {
if (!storage_copied)
return NULL;
if (!bdev) {
if (!newc) {
if (!container_destroy(c)) {
static int lxcapi_attach(struct lxc_container *c, lxc_attach_exec_t exec_function, void *exec_payload, lxc_attach_options_t *options, pid_t *attached_process)
static int lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char * const argv[])
char *fname;
int i = 0, ret;
if (ret != 0)
int ret;
if (!c || !lxcapi_is_defined(c))
if (!c2) {
FILE *f;
fclose(f);
if (ret != 0) {
if (commentfile) {
if (s->name)
if (s->comment_pathname)
if (s->timestamp)
if (s->lxcpath)
free(s);
s = NULL;
return NULL;
if (!fin)
return NULL;
if (len > 0) {
free(s);
s = NULL;
if (!c || !lxcapi_is_defined(c))
if (!dir) {
if (!direntp)
goto out_free;
if (!nsnaps) {
goto out_free;
goto out_free;
goto out_free;
count++;
return count;
if (snaps) {
for (i=0; i<count; i++)
static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname)
int flags = 0;
if (has_fs_snapshots(c)) {
if (!bdev) {
if (!newname)
if (!container_destroy(c)) {
if (rest)
bool bret = false;
if (!snap) {
goto err;
goto err;
bret = true;
err:
if (snap)
return bret;
bool bret = true;
if (!dir) {
if (!direntp)
bret = false;
return bret;
int ret;
if (pid) {
if (!add)
exit(0);
exit(0);
static bool add_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path, bool add)
int ret;
if (!c->is_running(c)) {
if (add) {
static bool lxcapi_add_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
if (am_unpriv()) {
static bool lxcapi_remove_device_node(struct lxc_container *c, const char *src_path, const char *dest_path)
if (am_unpriv()) {
struct criu_opts {
char *action;
char *directory;
struct lxc_container *c;
bool verbose;
bool stop;
char *pidfile;
int ret;
FILE *f;
fclose(f);
if (ret <= 0)
* --action-script foo.sh -D $(directory) -o $(directory)/$(action).log
static_args++;
static_args++;
if (!argv)
goto err; \
goto err;
goto err;
int netnr = 0;
goto err;
goto err;
goto err;
goto err;
argv = m;
netnr++;
err:
for (i = 0; argv[i]; i++)
bool found_deny_rule = false;
if (geteuid()) {
// These requirements come from http://criu.org/LXC
found_deny_rule = true;
if (!found_deny_rule) {
bool error = false;
if (!criu_ok(c))
netnr = 0;
int pret;
error = true;
goto out;
if (!veth) {
error = true;
goto out;
if (!bridge) {
error = true;
goto out;
error = true;
goto out;
error = true;
goto out;
if (n->name) {
error = true;
goto out;
error = true;
out:
if (error)
if (pid < 0)
if (pid == 0) {
os.c = c;
if (!criu_ok(c))
if (geteuid()) {
if (!handler)
if (pid < 0)
if (pid == 0) {
os.c = c;
int status;
bool error = false;
fclose(f);
if (container_mem_lock(c))
error = true;
goto out_unlock;
error = true;
goto out_unlock;
error = true;
goto out_unlock;
netnr++;
if (error)
static int lxcapi_attach_run_waitl(struct lxc_container *c, lxc_attach_options_t *options, const char *program, const char *arg, ...)
const char **argv;
int ret;
if (!argv) {
return ret;
struct lxc_container *c;
if (!name)
return NULL;
c = malloc(sizeof(*c));
return NULL;
memset(c, 0, sizeof(*c));
if (configpath)
if (!c->config_path) {
goto err;
if (!c->name) {
goto err;
goto err;
goto err;
if (!set_config_filename(c)) {
goto err;
goto err;
c->daemonize = true;
goto err;
err:
return NULL;
if (states)
for (i=0; i<MAX_STATE; i++)
return MAX_STATE;
struct lxc_container *c;
if (!lxcpath)
if (!dir) {
if (cret)
if (names)
if (!direntp)
if (names) {
goto free_bad;
cfound++;
if (!cret) {
nfound++;
if (names)
goto free_bad;
if (!lxcapi_is_defined(c)) {
if (names)
goto free_bad;
goto free_bad;
nfound++;
return nfound;
for (i=0; i<cfound; i++)
for (i=0; i<nfound; i++)
int lxcpath_len;
struct lxc_container *c;
if (!lxcpath)
if (cret)
if (nret)
p += lxcpath_len;
goto free_cret_list;
ct_name_cnt++;
if (!cret)
lxcpath, p);
goto free_cret_list;
cret_cnt++;
if (nret)
goto free_ct_name;
goto out;
for (i = 0; i < cret_cnt; i++)
if (ct_name) {
for (i = 0; i < ct_name_cnt; i++)
out:
if (line)
fclose(f);
return ret;
char **active_name;
char **ct_name;
if (ct_cnt < 0)
return ct_cnt;
if (active_cnt < 0) {
goto free_ct_name;
for (i = 0; i < active_cnt; i++) {
goto free_active_name;
ct_cnt++;
active_cnt = 0;
struct lxc_container *c;
goto free_ct_list;
ct_list_cnt++;
if (cret)
if (nret)
goto free_ct_name;
return ct_cnt;
for (i = 0; i < ct_list_cnt; i++) {
if (ct_list)
for (i = 0; i < active_cnt; i++) {
if (active_name[i])
if (active_name)
for (i = 0; i < ct_cnt; i++) {
return ret;