</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>-P, --lxcpath=<replaceable>PATH</replaceable></option></term>
+ <listitem>
+ <para>
+ Use an alternate container path. The default is @LXCPATH@.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>-o, --logfile=<replaceable>FILE</replaceable></option></term>
<listitem>
}
static int lxc_default_config_path_get(lua_State *L) {
- char *lxcpath = lxc_get_default_config_path();
+ const char *lxcpath = lxc_get_default_config_path();
lua_pushstring(L, lxcpath);
- free(lxcpath);
return 1;
}
#include <unistd.h>
#include "arguments.h"
+#include "utils.h"
/*---------------------------------------------------------------------------*/
static int build_shortopts(const struct option *a_options,
-o, --logfile=FILE Output log to FILE instead of stderr\n\
-l, --logpriority=LEVEL Set log priority to LEVEL\n\
-q, --quiet Don't produce any output\n\
+ -P, --lxcpath=PATH Use specified container path\n\
-?, --help Give this help list\n\
--usage Give a short usage message\n\
\n\
char shortopts[256];
int ret = 0;
+ args->lxcpath = default_lxc_path();
ret = build_shortopts(args->options, shortopts, sizeof(shortopts));
if (ret < 0) {
lxc_error(args, "build_shortopts() failed : %s",
case 'l': args->log_priority = optarg; break;
case 'c': args->console = optarg; break;
case 'q': args->quiet = 1; break;
+ case 'P': args->lxcpath = optarg; break;
case OPT_USAGE: print_usage(args->options, args);
case '?': print_help(args, 1);
case 'h': print_help(args, 0);
const char *console;
const char *console_log;
const char *pidfile;
+ const char *lxcpath;
/* for lxc-checkpoint/restart */
const char *statefile;
{"quiet", no_argument, 0, 'q'}, \
{"logfile", required_argument, 0, 'o'}, \
{"logpriority", required_argument, 0, 'l'}, \
+ {"lxcpath", required_argument, 0, 'P'}, \
{0, 0, 0, 0}
/* option keys for long only options */
static int fill_sock_name(char *path, int len, const char *name,
const char *inpath)
{
- char *lxcpath = NULL;
+ const char *lxcpath = NULL;
int ret;
if (!inpath) {
}
}
ret = snprintf(path, len, "%s/%s/command", lxcpath ? lxcpath : inpath, name);
- if (lxcpath)
- free(lxcpath);
if (ret < 0 || ret >= len) {
ERROR("Name too long");
unsigned long mntflags;
char *mntdata;
int r, ret = 0, offset;
- char *lxcpath;
+ const char *lxcpath;
if (parse_mntopts(mntent->mnt_opts, &mntflags, &mntdata) < 0) {
ERROR("failed to parse mount option '%s'", mntent->mnt_opts);
/* if rootfs->path is a blockdev path, allow container fstab to
* use $lxcpath/CN/rootfs as the target prefix */
r = snprintf(path, MAXPATHLEN, "%s/%s/rootfs", lxcpath, lxc_name);
- free(lxcpath);
if (r < 0 || r >= MAXPATHLEN)
goto skipvarlib;
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+. @DATADIR@/lxc/lxc.functions
+
usage() {
echo "usage: $(basename $0) -n NAME [-f CONFIG_FILE] [-t TEMPLATE] [FS_OPTIONS] --" >&2
- echo " [TEMPLATE_OPTIONS]" >&2
+ echo " [-P lxcpath] [TEMPLATE_OPTIONS]" >&2
echo >&2
echo "where FS_OPTIONS is one of:" >&2
echo " -B none" >&2
echo " -f CONFIG_FILE use an existing configuration file" >&2
echo " -t TEMPLATE use an accessible template script" >&2
echo " -B BACKING_STORE alter the container backing store (default: none)" >&2
+ echo " --lxcpath path specify an alternate container patch (default: $lxc_path)" >&2
echo " --lvname LV_NAME specify the LVM logical volume name" >&2
echo " (default: container name)" >&2
echo " --dir ROOTFS_DIR specify path for custom rootfs directory location" >&2
fi
}
-. @DATADIR@/lxc/lxc.functions
backingstore=_unset
fstype=ext4
fssize=500M
lxc_config=$1
shift
;;
+ -P|--lxcpath)
+ optarg_check $opt "$1"
+ lxc_path=$1
+ shift
+ ;;
-t|--template)
optarg_check $opt "$1"
lxc_template=$1
* @sfd: fd from which the container is restarted
* @conf: lxc_conf structure.
* @flags : restart flags (an ORed value)
+ * @lxcpath: container path
* Returns 0 on success, < 0 otherwise
*/
-extern int lxc_restart(const char *, int, struct lxc_conf *, int);
+extern int lxc_restart(const char *, int, struct lxc_conf *, int, const char *);
/*
* Returns the version number of the library
void *cgroup_data = NULL;
uid_t uid;
char *curdir;
- /* TODO: add cmdline arg to set lxcpath */
- const char *lxcpath = NULL;
ret = lxc_caps_init();
if (ret)
if (ret)
return ret;
- init_pid = get_init_pid(my_args.name, lxcpath);
+ init_pid = get_init_pid(my_args.name, my_args.lxcpath);
if (init_pid < 0) {
ERROR("failed to get the init pid");
return -1;
* by asking lxc-start
*/
if (namespace_flags == -1) {
- namespace_flags = lxc_get_clone_flags(my_args.name, lxcpath);
+ namespace_flags = lxc_get_clone_flags(my_args.name, my_args.lxcpath);
/* call failed */
if (namespace_flags == -1) {
ERROR("failed to automatically determine the "
int err, std_in = 1;
struct lxc_epoll_descr descr;
struct termios newtios, oldtios;
- /* TODO: add cmdline arg to specify lxcpath */
- char *lxcpath = NULL;
err = lxc_arguments_parse(&my_args, argc, argv);
if (err)
return -1;
}
- err = lxc_console(my_args.name, my_args.ttynum, &master, lxcpath);
+ err = lxc_console(my_args.name, my_args.ttynum, &master, my_args.lxcpath);
if (err)
goto out;
rcfile = (char *)my_args.rcfile;
else {
int rc;
- char *lxcpath = default_lxc_path();
- if (!lxcpath) {
- ERROR("Out of memory");
- return -1;
- }
- rc = asprintf(&rcfile, "%s/%s/config", lxcpath, my_args.name);
- free(lxcpath);
+ rc = asprintf(&rcfile, "%s/%s/config", my_args.lxcpath, my_args.name);
if (rc == -1) {
SYSERROR("failed to allocate memory");
return -1;
if (lxc_config_define_load(&defines, conf))
return -1;
- return lxc_execute(my_args.name, my_args.argv, my_args.quiet, conf, NULL);
+ return lxc_execute(my_args.name, my_args.argv, my_args.quiet, conf, my_args.lxcpath);
}
int main(int argc, char *argv[])
{
int ret;
- /* TODO: add lxcpath cmdline arg */
- const char *lxcpath = NULL;
ret = lxc_arguments_parse(&my_args, argc, argv);
if (ret)
state = pid = true;
if (state || test_state) {
- ret = lxc_getstate(my_args.name, lxcpath);
+ ret = lxc_getstate(my_args.name, my_args.lxcpath);
if (ret < 0)
return 1;
if (test_state)
}
if (pid)
- printf("pid:%10d\n", get_init_pid(my_args.name, lxcpath));
+ printf("pid:%10d\n", get_init_pid(my_args.name, my_args.lxcpath));
return 0;
}
int ret;
pid_t pid;
int sig;
- /* TODO: add lxcpath cmdline arg */
- const char *lxcpath = NULL;
ret = lxc_arguments_parse(&my_args, argc, argv);
if (ret)
} else
sig=SIGKILL;
- pid = get_init_pid(my_args.name, lxcpath);
+ pid = get_init_pid(my_args.name, my_args.lxcpath);
if (pid < 0) {
ERROR("failed to get the init pid");
return -1;
rcfile = (char *)my_args.rcfile;
else {
int rc;
- char *lxcpath = default_lxc_path();
- if (!lxcpath) {
- ERROR("Out of memory");
- return -1;
- }
- rc = asprintf(&rcfile, "%s/%s/config", lxcpath, my_args.name);
- free(lxcpath);
+ rc = asprintf(&rcfile, "%s/%s/config", my_args.lxcpath, my_args.name);
if (rc == -1) {
SYSERROR("failed to allocate memory");
return -1;
}
}
- ret = lxc_restart(my_args.name, sfd, conf, my_args.flags);
+ ret = lxc_restart(my_args.name, sfd, conf, my_args.flags, my_args.lxcpath);
if (my_args.statefile)
close(sfd);
'\0',
};
FILE *pid_fp = NULL;
- /* TODO: add cmdline arg to specify lxcpath */
- char *lxcpath = NULL;
lxc_list_init(&defines);
rcfile = (char *)my_args.rcfile;
else {
int rc;
- char *lxcpath = default_lxc_path();
- if (!lxcpath) {
- ERROR("Out of memory");
- return -1;
- }
- rc = asprintf(&rcfile, "%s/%s/config", lxcpath, my_args.name);
- free(lxcpath);
+ rc = asprintf(&rcfile, "%s/%s/config", my_args.lxcpath, my_args.name);
if (rc == -1) {
SYSERROR("failed to allocate memory");
return err;
if (my_args.close_all_fds)
conf->close_all_fds = 1;
- err = lxc_start(my_args.name, args, conf, lxcpath);
+ err = lxc_start(my_args.name, args, conf, my_args.lxcpath);
/*
* exec ourself, that requires to have all opened fd
#include <lxc/log.h>
#include "arguments.h"
+#include "utils.h"
static const struct option my_longopts[] = {
LXC_COMMON_OPTIONS
int main(int argc, char *argv[])
{
- /* TODO - make lxcpath a cmdline arg */
- const char *lxcpath = NULL;
-
if (lxc_arguments_parse(&my_args, argc, argv))
return -1;
my_args.progname, my_args.quiet))
return -1;
- return lxc_stop(my_args.name, lxcpath);
+ return lxc_stop(my_args.name, my_args.lxcpath);
}
my_args.progname, my_args.quiet))
return -1;
- return lxc_wait(strdup(my_args.name), my_args.states, my_args.timeout);
+ return lxc_wait(strdup(my_args.name), my_args.states, my_args.timeout, my_args.lxcpath);
}
if (!c)
return false;
- ret = lxc_wait(c->name, state, timeout);
+ ret = lxc_wait(c->name, state, timeout, c->config_path);
return ret == 0;
}
return ret;
}
-char *lxc_get_default_config_path(void)
+const char *lxc_get_default_config_path(void)
{
return default_lxc_path();
}
if (configpath)
c->config_path = strdup(configpath);
else
- c->config_path = default_lxc_path();
+ c->config_path = strdup(default_lxc_path());
if (!c->config_path) {
fprintf(stderr, "Out of memory");
int lxc_container_get(struct lxc_container *c);
int lxc_container_put(struct lxc_container *c);
int lxc_get_wait_states(const char **states);
-char *lxc_get_default_config_path(void);
+const char *lxc_get_default_config_path(void);
#if 0
char ** lxc_get_valid_keys();
.post_start = post_restart
};
-int lxc_restart(const char *name, int sfd, struct lxc_conf *conf, int flags)
+int lxc_restart(const char *name, int sfd, struct lxc_conf *conf, int flags,
+ const char *lxcpath)
{
struct restart_args restart_arg = {
.sfd = sfd,
.flags = flags
};
- /* TODO - make lxcpath a cmdline arg */
- const char *lxcpath = NULL;
if (lxc_check_inherited(conf, sfd))
return -1;
return 0;
}
-extern int lxc_wait(const char *lxcname, const char *states, int timeout)
+extern int lxc_wait(const char *lxcname, const char *states, int timeout, const char *lxcpath)
{
struct lxc_msg msg;
int state, ret;
int s[MAX_STATE] = { }, fd;
- /* TODO: add cmdline arg to specify lxcpath */
- char *lxcpath = NULL;
if (fillwaitedstates(states, s))
return -1;
extern lxc_state_t lxc_str2state(const char *state);
extern const char *lxc_state2str(lxc_state_t state);
-extern int lxc_wait(const char *lxcname, const char *states, int timeout);
+extern int lxc_wait(const char *lxcname, const char *states, int timeout, const char *lxcpath);
#endif
return retbuf;
}
-char *default_lxc_path(void)
+char *default_lxcpath;
+
+const char *default_lxc_path(void)
{
- char buf[1024], *p, *retbuf;
+ char buf[1024], *p;
FILE *fin;
+ if (default_lxcpath)
+ return default_lxcpath;
+
fin = fopen(LXC_GLOBAL_CONF, "r");
if (fin) {
while (fgets(buf, 1024, fin)) {
while (*p && (*p == ' ' || *p == '\t')) p++;
if (!*p)
continue;
- retbuf = copypath(p);
+ default_lxcpath = copypath(p);
goto out;
}
}
/* we couldn't open the file, or didn't find a lxcpath
* entry there. Return @LXCPATH@ */
- retbuf = malloc(strlen(LXCPATH)+1);
- if (!retbuf)
- goto out;
- strcpy(retbuf, LXCPATH);
+ default_lxcpath = LXCPATH;
out:
if (fin)
fclose(fin);
- INFO("returning %s", (retbuf ? retbuf : "null"));
- return retbuf;
+ return default_lxcpath;
}
* Return a newly allocated buffer containing the default container
* path. Caller must free this buffer.
*/
-extern char *default_lxc_path(void);
+extern const char *default_lxc_path(void);
#endif