lxc_start.c revision 6c544cb300752a9f799cda19e9c5b57ab890c8dd
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <daniel.lezcano at free.fr>
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 <lxc/lxccontainer.h>
#include "conf.h"
#include "cgroup.h"
#include "utils.h"
#include "config.h"
#include "confile.h"
#include "arguments.h"
{
if (path) {
goto err;
}
if (fd >= 0)
}
if (!fullpath) {
goto err;
}
if (!*confpath) {
goto err;
}
}
err = 0;
err:
if (fullpath)
return err;
}
char *eptr;
struct lxc_container *s;
if (!s) {
return -1;
}
if (!s->may_control(s)) {
return -1;
}
if (pid < 1) {
return -1;
}
}
return -1;
}
return pid;
}
int fd;
char path[MAXPATHLEN];
if (fd < 0) {
return -1;
}
return fd;
}
{
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\
--share-net=NAME Share a network namespace with another container or pid\n\
--share-ipc=NAME Share an IPC namespace with another container or pid\n\
--share-uts=NAME Share a UTS namespace with another container or pid\n\
",
.options = my_longopts,
.daemonize = 0,
};
{
int err = -1;
char *const *args;
char *const default_args[] = {
'\0',
};
struct lxc_container *c;
if (lxc_caps_init())
return err;
return err;
args = default_args;
else
return err;
/*
* rcfile possibilities:
* 1. rcfile from random path specified in cli option
* 3. rcfile not specified and does not exist.
*/
/* rcfile is specified in the cli option */
if (!c) {
ERROR("Failed to create lxc_container");
return err;
}
if (!c->load_config(c, rcfile)) {
ERROR("Failed to load rcfile");
return err;
}
} else {
int rc;
if (rc == -1) {
SYSERROR("failed to allocate memory");
return err;
}
/* container configuration does not exist */
}
if (!c) {
ERROR("Failed to create lxc_container");
return err;
}
}
/*
* We should use set_config_item() over &defines, which would handle
* unset c->lxc_conf for us and let us not use lxc_config_define_load()
*/
if (!c->lxc_conf)
c->lxc_conf = lxc_conf_init();
goto out;
goto out;
}
goto out;
}
goto out;
}
SYSERROR("failed to create pidfile '%s' for '%s'",
goto out;
}
}
int i;
for (i = 0; i < LXC_NS_MAX; i++) {
continue;
if (pid < 1)
goto out;
if (fd < 0)
goto out;
}
c->want_daemonize(c);
}
goto out;
}
}
if (my_args.close_all_fds)
c->want_close_all_fds(c);
out:
return err;
}