start.c revision 5e97c3fcce787a5bc0f8ceef43aa3e05195b480a
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <dlezcano at fr.ibm.com>
*
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <mntent.h>
#include <lxc.h>
#include <namespace.h>
#include <network.h>
#include <state.h>
#include <cgroup.h>
#include <utils.h>
#include <list.h>
#include <conf.h>
#include <log.h>
#include <lock.h>
{
int clone_flags;
if (!lock) {
return -1;
}
if (lock < 0) {
lxc_log_error("failed to acquire lock on '%s':%s",
return -1;
}
/* Begin the set the state to STARTING*/
goto out;
}
/* Synchro socketpair */
lxc_log_syserror("failed to create communication socketpair");
goto err;
}
/* Avoid signals from terminal */
if (conf_has_fstab(name))
if (conf_has_utsname(name))
if (conf_has_network(name))
/* Create a process in a new set of namespaces */
if (pid < 0) {
lxc_log_syserror("failed to fork into a new namespace");
goto err_fork_ns;
}
if (!pid) {
/* Be sure we don't inherit this after the exec */
/* Tell our father he can begin to configure the container */
lxc_log_syserror("failed to write socket");
return 1;
}
/* Wait for the father to finish the configuration */
lxc_log_syserror("failed to read socket");
return 1;
}
/* Setup the container, ip, names, utsname, ... */
lxc_log_error("failed to setup the container");
lxc_log_syserror("failed to write the socket");
return -1;
}
/* If a callback has been passed, call it before doing exec */
if (prestart)
lxc_log_error("prestart callback has failed");
return -1;
}
/* If the exec fails, tell that to our father */
lxc_log_syserror("failed to write the socket");
return 1;
}
/* Wait for the child to be ready */
lxc_log_syserror("failed to read the socket");
goto err_pipe_read;
}
/* Create the network configuration */
lxc_log_error("failed to create the configured network");
goto err_create_network;
}
/* Tell the child to continue its initialization */
lxc_log_syserror("failed to write the socket");
goto err_pipe_write;
}
/* Wait for the child to exec or returning an error */
if (err < 0) {
lxc_log_error("failed to read the socket");
goto err_pipe_read2;
}
if (err > 0) {
/* TODO : check status etc ... */
goto err_child_failed;
}
if (fd < 0) {
goto err_write;
}
lxc_log_syserror("failed to write the init pid");
goto err_write;
}
lxc_log_warning("cgroupfs not found: cgroup disabled");
goto err_state_failed;
}
goto wait_again;
goto err_waitpid_failed;
}
lxc_log_error("failed to destroy the network");
err = 0;
out:
return err;
if (clone_flags & CLONE_NEWNET)
err:
goto out;
}