lxc_start.c revision 596a818d4b8b55586d36af518b745cd96b24c67a
/*
* 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 <libgen.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <termios.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include "log.h"
#include "caps.h"
#include "lxc.h"
#include "conf.h"
#include "cgroup.h"
#include "utils.h"
#include "config.h"
#include "confile.h"
#include "arguments.h"
{
if (path) {
if (fd < 0) {
goto err;
}
}
if (!fullpath) {
goto err;
}
if (!*confpath) {
goto err;
}
}
err = 0;
err:
if (fullpath)
return err;
}
{
switch (c) {
}
return 0;
}
static const struct option my_longopts[] = {
};
static struct lxc_arguments my_args = {
.progname = "lxc-start",
.help = "\
--name=NAME -- COMMAND\n\
\n\
lxc-start start COMMAND in specified container NAME\n\
\n\
Options :\n\
-n, --name=NAME NAME for name of the container\n\
-d, --daemon daemonize the container\n\
-p, --pidfile=FILE Create a file with the process id\n\
-f, --rcfile=FILE Load configuration file FILE\n\
-c, --console=FILE Use specified FILE for the container console\n\
-L, --console-log=FILE Log container console output to FILE\n\
-C, --close-all-fds If any fds are inherited, close them\n\
If not specified, exit with failure instead\n\
Note: --daemon implies --close-all-fds\n\
-s, --define KEY=VAL Assign VAL to configuration variable KEY\n",
.options = my_longopts,
.daemonize = 0,
};
{
int err = -1;
char *const *args;
char *const default_args[] = {
'\0',
};
if (lxc_caps_init())
return err;
return err;
args = default_args;
else
return err;
if (clearenv()) {
SYSERROR("failed to clear environment");
/* don't error out though */
}
if (putenv("container=lxc")) {
SYSERROR("failed to set environment variable");
return err;
}
/* rcfile is specified in the cli option */
else {
int rc;
if (rc == -1) {
SYSERROR("failed to allocate memory");
return err;
}
/* container configuration does not exist */
}
}
conf = lxc_conf_init();
if (!conf) {
ERROR("failed to initialize configuration");
return err;
}
ERROR("failed to read configuration file");
return err;
}
return err;
return err;
}
return err;
}
return err;
}
SYSERROR("failed to create pidfile '%s' for '%s'",
return err;
}
}
/* do an early check for needed privs, since otherwise the
* user won't see the error */
if (!lxc_caps_check()) {
ERROR("Not running with sufficient privilege");
return err;
}
if (daemon(0, 0)) {
return err;
}
}
return err;
}
}
if (my_args.close_all_fds)
/*
* exec ourself, that requires to have all opened fd
* with the close-on-exec flag set
*/
INFO("rebooting container");
SYSERROR("failed to exec");
err = -1;
}
return err;
}