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