lxccontainer.c revision 9123e4718d0db98de2a2935cb2d0bcca1997a333
1057N/A * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>. 1057N/A * Copyright © 2012 Canonical Ltd. 1057N/A * This program is free software; you can redistribute it and/or modify 660N/A * it under the terms of the GNU General Public License version 2, as 1057N/A * published by the Free Software Foundation. 1057N/A * This program is distributed in the hope that it will be useful, 1057N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of 1057N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1057N/A * GNU General Public License for more details. 1057N/A * You should have received a copy of the GNU General Public License along 1057N/A * with this program; if not, write to the Free Software Foundation, Inc., 1057N/A * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 1109N/A * c->privlock protects the struct lxc_container from multiple threads. 684N/A * c->slock protects the on-disk container data 684N/A * NOTHING mutexes two independent programs with their own struct 684N/A * lxc_container for the same c->name, between API calls. For instance, 684N/A * c->config_read(); c->start(); Between those calls, data on disk 684N/A * could change (which shouldn't bother the caller unless for instance 684N/A * the rootfs get moved). c->config_read(); update; c->config_write(); 684N/A * Two such updaters could race. The callers should therefore check their 1109N/A * results. Trying to prevent that would necessarily expose us to deadlocks 1057N/A * due to hung callers. So I prefer to keep the locks only within our own 1057N/A * functions, not across functions. 684N/A * If you're going to fork while holding a lxccontainer, increment 684N/A * c->numthreads (under privlock) before forking. When deleting, 684N/A * decrement numthreads under privlock, then if it hits 0 you can delete. 684N/A * Do not ever use a lxccontainer whose numthreads you did not bump. 684N/A // bail without trying to unlock, bc the privlock is now probably 684N/A /* we'll probably want to make this timeout configurable? */ 684N/A * our child is going to fork again, then exit. reap the 684N/A DEBUG(
"failed waiting for first dual-fork child");
684N/A * I can't decide if it'd be more convenient for callers if we accept '...', 1109N/A * or a null-terminated array (i.e. execl vs execv) 684N/A /* container has been setup */ 679N/A /* is this app meant to be run through lxcinit, as in lxc-execute? */ 1109N/A * say, I'm not sure - what locks do we want here? Any? 1109N/A * Is liblxc's locking enough here to protect the on disk 1109N/A * container? We don't want to exclude things like lxc_info 1109N/A * while container is running... 1057N/A /* second fork to be reparented by init */ 1109N/A /* like daemon(), chdir to / and redirect 0,1,2 to /dev/null */ 1109N/A /* don't error out though */ 1057N/A * note there MUST be an ending NULL 1109N/A /* build array of arguments if any */ 1057N/A * create the standard expected container dir 1057N/A * backing stores not (yet) supported 1057N/A * for ->create, argv contains the arguments to pass to the template, 1057N/A * terminated by NULL. If no arguments, you can just pass NULL. 1057N/A /* we're going to fork. but since we'll wait for our child, we 1109N/A don't need to lxc_container_get */ 1057N/A * create our new array, pre-pend the template name and 1109N/A // we could set an error code and string inside the 1057N/A // container_struct here if we like 1057N/A ERROR(
"container creation template exited abnormally\n");
725N/A ERROR(
"container creation template for %s exited with %d\n",
1057N/A // now clear out the lxc_conf we have, reload from the created 1057N/A * since we're going to wait for create to finish, I don't think we 1057N/A * need to get a copy of the arguments. 684N/A * Support 'lxc.network.<idx>', i.e. 'lxc.network.0' 684N/A * This is an intelligent result to show which keys are valid given 1109N/A/* default config file - should probably come through autoconf */ 684N/A return false;
// should we write to stdout if no file is specified? 684N/A // we could set an error code and string inside the 684N/A // container_struct here if we like 1109N/A * Just recalculate the c->configfile based on the 1057N/A * c->config_path, which must be set. 1057N/A * The lxc_container must be locked or not yet public. 679N/A /* $lxc_path + "/" + c->name + "/" + "config" + '\0' */ 1109N/A /* Since we've changed the config path, we have to change the 1109N/A // assign the member functions 1109N/A /* we'll allow the caller to update these later */