[lxc-devel] [PATCH] pass lxcpath to lxc_command

Dwight Engen dwight.engen at oracle.com
Tue Feb 12 14:55:12 UTC 2013


On Mon, 11 Feb 2013 16:40:39 -0500
Stéphane Graber <stgraber at ubuntu.com> wrote:

> On 02/11/2013 03:43 PM, Serge Hallyn wrote:
> > 
> > The previous lxcpath patches added support for a custom LXCPATH set
> > through a system-wide configuration file.
> > 
> > This was also exposed through the C api, so that a custom lxcpath
> > could be set at the container object instanciation time, or set at
> > runtime.
> > 
> > However the command sock filename was always located under the
> > global lxcpath, which could be confusing, and would be a problem
> > for users with insufficient perms to the system-wide lxc path (i.e.
> > if setting lxcpath to $HOME/lxcbase).  This patch changes that by
> > passing the lxcpath to all callers of lxc_command().
> > 
> > It remains to add an lxcpath command line argument to most of the
> > command line tools (which are not using the C api) - lxc-start,
> > lxc-info, lxc-stop, etc.
> > 
> > At this point it becomes tempting to do something like
> > 
> > 	c = lxc.Container("r1", "/var/lib/lxc")
> > 	c2 = lxc.Container("r1", "$HOME/lxcbase")
> > 
> > However, that's problematic - those two will use the same directory
> > names for cgroup directories.
> > 
> > What would be the best way to handle this?  One way (which I kind
> > of like) is to give up on naming the cgroups after the container.
> > use mkstemp for the cgroup name, let lxc keep track of the cgroup
> > name based on the command socket, and make users use lxc-cgroup to
> > get and change settings.
> 
> As we discussed on IRC, I think it'd be best to do two things:
> 1) Add a new lxc.cgroup.directory option which would default to "lxc"
> (our current directory) and let people easily override to another name
> to avoid the conflict.

I like this, and I think it might also allow for groups of containers I
was refering to in irc with a little more support in the config file
for setting limits at the directory level (at least to a grouping depth
of 1). For example lets say a config file looks like:

 lxc.cgroup.directory = builds
 lxc.cgroup.directory.memory.limit_in_bytes = 1073741824

This would set /sys/fs/cgroup/memory/builds/memory.limit_in_bytes which
would limit all containers in the "group" builds together to 1G. Any
config file that specifies lxc.cgroup.directory = builds is under the
"group", but it only makes sense to set the limits in one config file.
Of course this also assumes we automatically
set /sys/fs/cgroup/*/<group>/*.use_heirarchy = 1. Thoughts?

> 2) Add a simple conflict checker in the cgroup code. If the cgroup
> path already exists, then simply prefix -X to the directory name,
> incrementing X as needed.
> 
> The main reason we found not to use mkstemp is that user space tools
> such as htop show the cgroup hierarchy which helps user identify which
> container a given process is running in. Having the name be random
> would require access to each processes's UTS namespace to retrieve
> the name and then some magic to figure out the nesting.

I agree that its nice to have the names as close as possible to what
the user would expect to see based on the container name. Since the
race fix in d2e30e99 won't prevent us from trying to create a duplicate
cgroup name when using a multiple command sockets, I guess we'll just
check for EEXIST on the mkdir as the atomic check?

> > Other ideas?
> > 
> > Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> 
> Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> 
> As I commented in my python commit earlier, we'll do a massive update
> of all the commands to add the lxcpath argument in a consistent way
> once alpha3 is out, so the changes below look good for alpha3.
> 
> I'm just waiting for a decision on what part of Dwight's change to
> merge before doing final testing and sending the pull request.
> 
> > ---
> >  src/lxc/commands.c     | 48
> > ++++++++++++++++++++++++++++++------------------
> > src/lxc/commands.h     | 11 ++++++----- src/lxc/console.c      |  4
> > ++-- src/lxc/execute.c      |  4 ++--
> >  src/lxc/lxc.h          | 11 ++++++-----
> >  src/lxc/lxc_attach.c   |  6 ++++--
> >  src/lxc/lxc_console.c  |  4 +++-
> >  src/lxc/lxc_execute.c  |  2 +-
> >  src/lxc/lxc_info.c     |  6 ++++--
> >  src/lxc/lxc_kill.c     |  4 +++-
> >  src/lxc/lxc_start.c    |  4 +++-
> >  src/lxc/lxc_stop.c     |  5 ++++-
> >  src/lxc/lxccontainer.c | 12 ++++++------
> >  src/lxc/restart.c      |  4 +++-
> >  src/lxc/start.c        | 13 +++++++------
> >  src/lxc/start.h        |  4 ++--
> >  src/lxc/state.c        | 12 +++++++-----
> >  src/lxc/state.h        |  2 +-
> >  src/lxc/stop.c         |  4 ++--
> >  19 files changed, 96 insertions(+), 64 deletions(-)
> > 
> > diff --git a/src/lxc/commands.c b/src/lxc/commands.c
> > index 2c4d603..2776f03 100644
> > --- a/src/lxc/commands.c
> > +++ b/src/lxc/commands.c
> > @@ -59,14 +59,23 @@
> >  
> >  lxc_log_define(lxc_commands, lxc);
> >  
> > -static int fill_sock_name(char *path, int len, const char *name) {
> > -	char *lxcpath = default_lxc_path();
> > +static int fill_sock_name(char *path, int len, const char *name,
> > +			  const char *inpath)
> > +{
> > +	char *lxcpath = NULL;
> >  	int ret;
> > -	if (!lxcpath) {
> > -		ERROR("Out of memory getting lxcpath");
> > -		return -1;
> > +
> > +	if (!inpath) {
> > +		lxcpath = default_lxc_path();
> > +		if (!lxcpath) {
> > +			ERROR("Out of memory getting lxcpath");
> > +			return -1;
> > +		}
> >  	}
> > -	ret = snprintf(path, len, "%s/%s/command", lxcpath, name);
> > +	ret = snprintf(path, len, "%s/%s/command", lxcpath ?
> > lxcpath : inpath, name);
> > +	if (lxcpath)
> > +		free(lxcpath);
> > +
> >  	if (ret < 0 || ret >= len) {
> >  		ERROR("Name too long");
> >  		return -1;
> > @@ -86,7 +95,7 @@ static int receive_answer(int sock, struct
> > lxc_answer *answer) }
> >  
> >  static int __lxc_command(const char *name, struct lxc_command
> > *command,
> > -			 int *stopped, int stay_connected)
> > +			 int *stopped, int stay_connected, const
> > char *lxcpath) {
> >  	int sock, ret = -1;
> >  	char path[sizeof(((struct sockaddr_un *)0)->sun_path)] =
> > { 0 }; @@ -94,7 +103,7 @@ static int __lxc_command(const char
> > *name, struct lxc_command *command, int len;
> >  
> >  	len = sizeof(path)-1;
> > -	if (fill_sock_name(offset, len, name))
> > +	if (fill_sock_name(offset, len, name, lxcpath))
> >  		return -1;
> >  
> >  	sock = lxc_af_unix_connect(path);
> > @@ -129,19 +138,21 @@ out:
> >  }
> >  
> >  extern int lxc_command(const char *name,
> > -		       struct lxc_command *command, int *stopped)
> > +		       struct lxc_command *command, int *stopped,
> > +		       const char *lxcpath)
> >  {
> > -	return __lxc_command(name, command, stopped, 0);
> > +	return __lxc_command(name, command, stopped, 0, lxcpath);
> >  }
> >  
> >  extern int lxc_command_connected(const char *name,
> > -				 struct lxc_command *command, int
> > *stopped)
> > +				 struct lxc_command *command, int
> > *stopped,
> > +				 const char *lxcpath)
> >  {
> > -	return __lxc_command(name, command, stopped, 1);
> > +	return __lxc_command(name, command, stopped, 1, lxcpath);
> >  }
> >  
> >  
> > -pid_t get_init_pid(const char *name)
> > +pid_t get_init_pid(const char *name, const char *lxcpath)
> >  {
> >  	struct lxc_command command = {
> >  		.request = { .type = LXC_COMMAND_PID },
> > @@ -149,7 +160,7 @@ pid_t get_init_pid(const char *name)
> >  
> >  	int ret, stopped = 0;
> >  
> > -	ret = lxc_command(name, &command, &stopped);
> > +	ret = lxc_command(name, &command, &stopped, lxcpath);
> >  	if (ret < 0 && stopped)
> >  		return -1;
> >  
> > @@ -167,7 +178,7 @@ pid_t get_init_pid(const char *name)
> >  	return command.answer.pid;
> >  }
> >  
> > -int lxc_get_clone_flags(const char *name)
> > +int lxc_get_clone_flags(const char *name, const char *lxcpath)
> >  {
> >  	struct lxc_command command = {
> >  		.request = { .type = LXC_COMMAND_CLONE_FLAGS },
> > @@ -175,7 +186,7 @@ int lxc_get_clone_flags(const char *name)
> >  
> >  	int ret, stopped = 0;
> >  
> > -	ret = lxc_command(name, &command, &stopped);
> > +	ret = lxc_command(name, &command, &stopped, lxcpath);
> >  	if (ret < 0 && stopped)
> >  		return -1;
> >  
> > @@ -300,7 +311,8 @@ out_close:
> >  	goto out;
> >  }
> >  
> > -extern int lxc_command_init(const char *name, struct lxc_handler
> > *handler) +extern int lxc_command_init(const char *name, struct
> > lxc_handler *handler,
> > +			    const char *lxcpath)
> >  {
> >  	int fd;
> >  	char path[sizeof(((struct sockaddr_un *)0)->sun_path)] =
> > { 0 }; @@ -308,7 +320,7 @@ extern int lxc_command_init(const char
> > *name, struct lxc_handler *handler) int len;
> >  
> >  	len = sizeof(path)-1;
> > -	if (fill_sock_name(offset, len, name))
> > +	if (fill_sock_name(offset, len, name, lxcpath))
> >  		return -1;
> >  
> >  	fd = lxc_af_unix_open(path, SOCK_STREAM, 0);
> > diff --git a/src/lxc/commands.h b/src/lxc/commands.h
> > index 0e1c8f9..0b72cf1 100644
> > --- a/src/lxc/commands.h
> > +++ b/src/lxc/commands.h
> > @@ -48,19 +48,20 @@ struct lxc_command {
> >  	struct lxc_answer answer;
> >  };
> >  
> > -extern pid_t get_init_pid(const char *name);
> > -extern int lxc_get_clone_flags(const char *name);
> > +extern pid_t get_init_pid(const char *name, const char *lxcpath);
> > +extern int lxc_get_clone_flags(const char *name, const char
> > *lxcpath); 
> >  extern int lxc_command(const char *name, struct lxc_command
> > *command,
> > -			int *stopped);
> > +			int *stopped, const char *lxcpath);
> >  
> >  extern int lxc_command_connected(const char *name, struct
> > lxc_command *command,
> > -				 int *stopped);
> > +				 int *stopped, const char
> > *lxcpath); 
> >  struct lxc_epoll_descr;
> >  struct lxc_handler;
> >  
> > -extern int lxc_command_init(const char *name, struct lxc_handler
> > *handler); +extern int lxc_command_init(const char *name, struct
> > lxc_handler *handler,
> > +			    const char *lxcpath);
> >  extern int lxc_command_mainloop_add(const char *name, struct
> > lxc_epoll_descr *descr, struct lxc_handler *handler);
> >  
> > diff --git a/src/lxc/console.c b/src/lxc/console.c
> > index 88aac84..cff7a92 100644
> > --- a/src/lxc/console.c
> > +++ b/src/lxc/console.c
> > @@ -46,14 +46,14 @@
> >  
> >  lxc_log_define(lxc_console, lxc);
> >  
> > -extern int lxc_console(const char *name, int ttynum, int *fd)
> > +extern int lxc_console(const char *name, int ttynum, int *fd,
> > const char *lxcpath) {
> >  	int ret, stopped = 0;
> >  	struct lxc_command command = {
> >  		.request = { .type = LXC_COMMAND_TTY, .data =
> > ttynum }, };
> >  
> > -	ret = lxc_command_connected(name, &command, &stopped);
> > +	ret = lxc_command_connected(name, &command, &stopped,
> > lxcpath); if (ret < 0 && stopped) {
> >  		ERROR("'%s' is stopped", name);
> >  		return -1;
> > diff --git a/src/lxc/execute.c b/src/lxc/execute.c
> > index 99800d0..18d2fb4 100644
> > --- a/src/lxc/execute.c
> > +++ b/src/lxc/execute.c
> > @@ -127,7 +127,7 @@ static struct lxc_operations execute_start_ops
> > = { };
> >  
> >  int lxc_execute(const char *name, char *const argv[], int quiet,
> > -		struct lxc_conf *conf)
> > +		struct lxc_conf *conf, const char *lxcpath)
> >  {
> >  	struct execute_args args = {
> >  		.argv = argv,
> > @@ -137,5 +137,5 @@ int lxc_execute(const char *name, char *const
> > argv[], int quiet, if (lxc_check_inherited(conf, -1))
> >  		return -1;
> >  
> > -	return __lxc_start(name, conf, &execute_start_ops, &args);
> > +	return __lxc_start(name, conf, &execute_start_ops, &args,
> > lxcpath); }
> > diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h
> > index a651d04..0e1ce63 100644
> > --- a/src/lxc/lxc.h
> > +++ b/src/lxc/lxc.h
> > @@ -47,7 +47,8 @@ struct lxc_arguments;
> >   * @conf     : configuration
> >   * Returns 0 on sucess, < 0 otherwise
> >   */
> > -extern int lxc_start(const char *name, char *const argv[], struct
> > lxc_conf *conf); +extern int lxc_start(const char *name, char
> > *const argv[], struct lxc_conf *conf,
> > +		     const char *lxcpath);
> >  
> >  /*
> >   * Stop the container previously started with lxc_start, all
> > @@ -55,7 +56,7 @@ extern int lxc_start(const char *name, char
> > *const argv[], struct lxc_conf *conf
> >   * @name : the name of the container
> >   * Returns 0 on success, < 0 otherwise
> >   */
> > -extern int lxc_stop(const char *name);
> > +extern int lxc_stop(const char *name, const char *lxcpath);
> >  
> >  /*
> >   * Start the specified command inside an application container
> > @@ -66,7 +67,7 @@ extern int lxc_stop(const char *name);
> >   * Returns 0 on sucess, < 0 otherwise
> >   */
> >  extern int lxc_execute(const char *name, char *const argv[], int
> > quiet,
> > -		       struct lxc_conf *conf);
> > +		       struct lxc_conf *conf, const char *lxcpath);
> >  
> >  /*
> >   * Open the monitoring mechanism for a specific container
> > @@ -100,7 +101,7 @@ extern int lxc_monitor_close(int fd);
> >   * @fd   : a pointer to a tty file descriptor
> >   * Returns 0 on sucess, < 0 otherwise
> >   */
> > -extern int lxc_console(const char *name, int ttynum, int *fd);
> > +extern int lxc_console(const char *name, int ttynum, int *fd,
> > const char *lxcpath); 
> >  /*
> >   * Freeze all the tasks running inside the container <name>
> > @@ -121,7 +122,7 @@ extern int lxc_unfreeze(const char *name);
> >   * @name : the name of the container
> >   * Returns the state of the container on success, < 0 otherwise
> >   */
> > -extern lxc_state_t lxc_state(const char *name);
> > +extern lxc_state_t lxc_state(const char *name, const char
> > *lxcpath); 
> >  /*
> >   * Set a specified value for a specified subsystem. The specified
> > diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c
> > index 437a400..b4ccf44 100644
> > --- a/src/lxc/lxc_attach.c
> > +++ b/src/lxc/lxc_attach.c
> > @@ -130,6 +130,8 @@ int main(int argc, char *argv[])
> >  	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)
> > @@ -144,7 +146,7 @@ int main(int argc, char *argv[])
> >  	if (ret)
> >  		return ret;
> >  
> > -	init_pid = get_init_pid(my_args.name);
> > +	init_pid = get_init_pid(my_args.name, lxcpath);
> >  	if (init_pid < 0) {
> >  		ERROR("failed to get the init pid");
> >  		return -1;
> > @@ -174,7 +176,7 @@ int main(int argc, char *argv[])
> >  	 * by asking lxc-start
> >  	 */
> >  	if (namespace_flags == -1) {
> > -		namespace_flags =
> > lxc_get_clone_flags(my_args.name);
> > +		namespace_flags =
> > lxc_get_clone_flags(my_args.name, lxcpath); /* call failed */
> >  		if (namespace_flags == -1) {
> >  			ERROR("failed to automatically determine
> > the " diff --git a/src/lxc/lxc_console.c b/src/lxc/lxc_console.c
> > index c263d0f..8ff3f5a 100644
> > --- a/src/lxc/lxc_console.c
> > +++ b/src/lxc/lxc_console.c
> > @@ -182,6 +182,8 @@ int main(int argc, char *argv[])
> >  	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)
> > @@ -198,7 +200,7 @@ int main(int argc, char *argv[])
> >  		return -1;
> >  	}
> >  
> > -	err = lxc_console(my_args.name, my_args.ttynum, &master);
> > +	err = lxc_console(my_args.name, my_args.ttynum, &master,
> > lxcpath); if (err)
> >  		goto out;
> >  
> > diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c
> > index 7a926a2..3c76e2e 100644
> > --- a/src/lxc/lxc_execute.c
> > +++ b/src/lxc/lxc_execute.c
> > @@ -143,5 +143,5 @@ int main(int argc, char *argv[])
> >  	if (lxc_config_define_load(&defines, conf))
> >  		return -1;
> >  
> > -	return lxc_execute(my_args.name, my_args.argv,
> > my_args.quiet, conf);
> > +	return lxc_execute(my_args.name, my_args.argv,
> > my_args.quiet, conf, NULL); }
> > diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c
> > index 48c1370..fb37b2f 100644
> > --- a/src/lxc/lxc_info.c
> > +++ b/src/lxc/lxc_info.c
> > @@ -74,6 +74,8 @@ Options :\n\
> >  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)
> > @@ -87,7 +89,7 @@ int main(int argc, char *argv[])
> >  		state = pid = true;
> >  
> >  	if (state || test_state) {
> > -		ret = lxc_getstate(my_args.name);
> > +		ret = lxc_getstate(my_args.name, lxcpath);
> >  		if (ret < 0)
> >  			return 1;
> >  		if (test_state)
> > @@ -97,7 +99,7 @@ int main(int argc, char *argv[])
> >  	}
> >  
> >  	if (pid)
> > -		printf("pid:%10d\n", get_init_pid(my_args.name));
> > +		printf("pid:%10d\n", get_init_pid(my_args.name,
> > lxcpath)); 
> >  	return 0;
> >  }
> > diff --git a/src/lxc/lxc_kill.c b/src/lxc/lxc_kill.c
> > index f9bfe34..669f469 100644
> > --- a/src/lxc/lxc_kill.c
> > +++ b/src/lxc/lxc_kill.c
> > @@ -56,6 +56,8 @@ int main(int argc, char *argv[], char *envp[])
> >  	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)
> > @@ -76,7 +78,7 @@ int main(int argc, char *argv[], char *envp[])
> >  	} else
> >  		sig=SIGKILL;
> >  
> > -	pid = get_init_pid(my_args.name);
> > +	pid = get_init_pid(my_args.name, lxcpath);
> >  	if (pid < 0) {
> >  		ERROR("failed to get the init pid");
> >  		return -1;
> > diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
> > index c50c36b..aac7fe7 100644
> > --- a/src/lxc/lxc_start.c
> > +++ b/src/lxc/lxc_start.c
> > @@ -150,6 +150,8 @@ int main(int argc, char *argv[])
> >  		'\0',
> >  	};
> >  	FILE *pid_fp = NULL;
> > +	/* TODO: add cmdline arg to specify lxcpath */
> > +	char *lxcpath = NULL;
> >  
> >  	lxc_list_init(&defines);
> >  
> > @@ -258,7 +260,7 @@ int main(int argc, char *argv[])
> >  	if (my_args.close_all_fds)
> >  		conf->close_all_fds = 1;
> >  
> > -	err = lxc_start(my_args.name, args, conf);
> > +	err = lxc_start(my_args.name, args, conf, lxcpath);
> >  
> >  	/*
> >  	 * exec ourself, that requires to have all opened fd
> > diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c
> > index 749d78a..703726a 100644
> > --- a/src/lxc/lxc_stop.c
> > +++ b/src/lxc/lxc_stop.c
> > @@ -50,6 +50,9 @@ Options :\n\
> >  
> >  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;
> >  
> > @@ -57,5 +60,5 @@ int main(int argc, char *argv[])
> >  			 my_args.progname, my_args.quiet))
> >  		return -1;
> >  
> > -	return lxc_stop(my_args.name);
> > +	return lxc_stop(my_args.name, lxcpath);
> >  }
> > diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> > index 733cbb6..3b816e5 100644
> > --- a/src/lxc/lxccontainer.c
> > +++ b/src/lxc/lxccontainer.c
> > @@ -161,7 +161,7 @@ static const char *lxcapi_state(struct
> > lxc_container *c) return NULL;
> >  	if (lxclock(c->slock, 0))
> >  		return NULL;
> > -	s = lxc_getstate(c->name);
> > +	s = lxc_getstate(c->name, c->config_path);
> >  	ret = lxc_state2str(s);
> >  	lxcunlock(c->slock);
> >  
> > @@ -171,7 +171,7 @@ static const char *lxcapi_state(struct
> > lxc_container *c) static bool is_stopped_nolock(struct
> > lxc_container *c) {
> >  	lxc_state_t s;
> > -	s = lxc_getstate(c->name);
> > +	s = lxc_getstate(c->name, c->config_path);
> >  	return (s == STOPPED);
> >  }
> >  
> > @@ -225,7 +225,7 @@ static pid_t lxcapi_init_pid(struct
> > lxc_container *c) 
> >  	if (lxclock(c->slock, 0))
> >  		return -1;
> > -	ret = get_init_pid(c->name);
> > +	ret = get_init_pid(c->name, c->config_path);
> >  	lxcunlock(c->slock);
> >  	return ret;
> >  }
> > @@ -324,7 +324,7 @@ static bool lxcapi_start(struct lxc_container
> > *c, int useinit, char * const argv lxcunlock(c->privlock);
> >  
> >  	if (useinit) {
> > -		ret = lxc_execute(c->name, argv, 1, conf);
> > +		ret = lxc_execute(c->name, argv, 1, conf,
> > c->config_path); return ret == 0 ? true : false;
> >  	}
> >  
> > @@ -386,7 +386,7 @@ static bool lxcapi_start(struct lxc_container
> > *c, int useinit, char * const argv 
> >  reboot:
> >  	conf->reboot = 0;
> > -	ret = lxc_start(c->name, argv, conf);
> > +	ret = lxc_start(c->name, argv, conf, c->config_path);
> >  
> >  	if (conf->reboot) {
> >  		INFO("container requested reboot");
> > @@ -464,7 +464,7 @@ static bool lxcapi_stop(struct lxc_container *c)
> >  	if (!c)
> >  		return false;
> >  
> > -	ret = lxc_stop(c->name);
> > +	ret = lxc_stop(c->name, c->config_path);
> >  
> >  	return ret == 0;
> >  }
> > diff --git a/src/lxc/restart.c b/src/lxc/restart.c
> > index a054838..d0b8fa8 100644
> > --- a/src/lxc/restart.c
> > +++ b/src/lxc/restart.c
> > @@ -70,9 +70,11 @@ int lxc_restart(const char *name, int sfd,
> > struct lxc_conf *conf, int flags) .sfd = sfd,
> >  		.flags = flags
> >  	};
> > +	/* TODO - make lxcpath a cmdline arg */
> > +	const char *lxcpath = NULL;
> >  
> >  	if (lxc_check_inherited(conf, sfd))
> >  		return -1;
> >  
> > -	return __lxc_start(name, conf, &restart_ops, &restart_arg);
> > +	return __lxc_start(name, conf, &restart_ops, &restart_arg,
> > lxcpath); }
> > diff --git a/src/lxc/start.c b/src/lxc/start.c
> > index 5083b24..139be08 100644
> > --- a/src/lxc/start.c
> > +++ b/src/lxc/start.c
> > @@ -363,7 +363,7 @@ out_sigfd:
> >  
> >  extern int lxc_caps_check(void);
> >  
> > -struct lxc_handler *lxc_init(const char *name, struct lxc_conf
> > *conf) +struct lxc_handler *lxc_init(const char *name, struct
> > lxc_conf *conf, const char *lxcpath) {
> >  	struct lxc_handler *handler;
> >  
> > @@ -387,7 +387,7 @@ struct lxc_handler *lxc_init(const char *name,
> > struct lxc_conf *conf) goto out_free;
> >  	}
> >  
> > -	if (lxc_command_init(name, handler))
> > +	if (lxc_command_init(name, handler, lxcpath))
> >  		goto out_free_name;
> >  
> >  	if (lxc_read_seccomp_config(conf) != 0) {
> > @@ -835,13 +835,13 @@ out_abort:
> >  }
> >  
> >  int __lxc_start(const char *name, struct lxc_conf *conf,
> > -		struct lxc_operations* ops, void *data)
> > +		struct lxc_operations* ops, void *data, const char
> > *lxcpath) {
> >  	struct lxc_handler *handler;
> >  	int err = -1;
> >  	int status;
> >  
> > -	handler = lxc_init(name, conf);
> > +	handler = lxc_init(name, conf, lxcpath);
> >  	if (!handler) {
> >  		ERROR("failed to initialize the container");
> >  		return -1;
> > @@ -940,7 +940,8 @@ static struct lxc_operations start_ops = {
> >  	.post_start = post_start
> >  };
> >  
> > -int lxc_start(const char *name, char *const argv[], struct
> > lxc_conf *conf) +int lxc_start(const char *name, char *const
> > argv[], struct lxc_conf *conf,
> > +	      const char *lxcpath)
> >  {
> >  	struct start_args start_arg = {
> >  		.argv = argv,
> > @@ -950,5 +951,5 @@ int lxc_start(const char *name, char *const
> > argv[], struct lxc_conf *conf) return -1;
> >  
> >  	conf->need_utmp_watch = 1;
> > -	return __lxc_start(name, conf, &start_ops, &start_arg);
> > +	return __lxc_start(name, conf, &start_ops, &start_arg,
> > lxcpath); }
> > diff --git a/src/lxc/start.h b/src/lxc/start.h
> > index 27688f3..8c8cbaf 100644
> > --- a/src/lxc/start.h
> > +++ b/src/lxc/start.h
> > @@ -52,7 +52,7 @@ struct lxc_handler {
> >  	int pinfd;
> >  };
> >  
> > -extern struct lxc_handler *lxc_init(const char *name, struct
> > lxc_conf *); +extern struct lxc_handler *lxc_init(const char *name,
> > struct lxc_conf *, const char *); extern int lxc_spawn(struct
> > lxc_handler *); 
> >  extern int lxc_poll(const char *name, struct lxc_handler *handler);
> > @@ -61,7 +61,7 @@ extern void lxc_fini(const char *name, struct
> > lxc_handler *handler); extern int lxc_set_state(const char *,
> > struct lxc_handler *, lxc_state_t); extern int
> > lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore); int
> > __lxc_start(const char *, struct lxc_conf *, struct lxc_operations
> > *,
> > -		void *);
> > +		void *, const char *);
> >  
> >  #endif
> >  
> > diff --git a/src/lxc/state.c b/src/lxc/state.c
> > index 7ce4b53..8552522 100644
> > --- a/src/lxc/state.c
> > +++ b/src/lxc/state.c
> > @@ -97,7 +97,7 @@ static int freezer_state(const char *name)
> >  	return lxc_str2state(status);
> >  }
> >  
> > -static lxc_state_t __lxc_getstate(const char *name)
> > +static lxc_state_t __lxc_getstate(const char *name, const char
> > *lxcpath) {
> >  	struct lxc_command command = {
> >  		.request = { .type = LXC_COMMAND_STATE },
> > @@ -105,7 +105,7 @@ static lxc_state_t __lxc_getstate(const char
> > *name) 
> >  	int ret, stopped = 0;
> >  
> > -	ret = lxc_command(name, &command, &stopped);
> > +	ret = lxc_command(name, &command, &stopped, lxcpath);
> >  	if (ret < 0 && stopped)
> >  		return STOPPED;
> >  
> > @@ -130,11 +130,11 @@ static lxc_state_t __lxc_getstate(const char
> > *name) return command.answer.ret;
> >  }
> >  
> > -lxc_state_t lxc_getstate(const char *name)
> > +lxc_state_t lxc_getstate(const char *name, const char *lxcpath)
> >  {
> >  	int state = freezer_state(name);
> >  	if (state != FROZEN && state != FREEZING)
> > -		state = __lxc_getstate(name);
> > +		state = __lxc_getstate(name, lxcpath);
> >  	return state;
> >  }
> >  
> > @@ -196,6 +196,8 @@ extern int lxc_wait(const char *lxcname, const
> > char *states, int timeout) 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;
> > @@ -209,7 +211,7 @@ extern int lxc_wait(const char *lxcname, const
> > char *states, int timeout)
> >  	 * then check if already in requested state
> >  	 */
> >  	ret = -1;
> > -	state = lxc_getstate(lxcname);
> > +	state = lxc_getstate(lxcname, lxcpath);
> >  	if (state < 0) {
> >  		goto out_close;
> >  	} else if ((state >= 0) && (s[state])) {
> > diff --git a/src/lxc/state.h b/src/lxc/state.h
> > index df8070a..c995e55 100644
> > --- a/src/lxc/state.h
> > +++ b/src/lxc/state.h
> > @@ -29,7 +29,7 @@ typedef enum {
> >  } lxc_state_t;
> >  
> >  extern int lxc_rmstate(const char *name);
> > -extern lxc_state_t lxc_getstate(const char *name);
> > +extern lxc_state_t lxc_getstate(const char *name, const char
> > *lxcpath); 
> >  extern lxc_state_t lxc_str2state(const char *state);
> >  extern const char *lxc_state2str(lxc_state_t state);
> > diff --git a/src/lxc/stop.c b/src/lxc/stop.c
> > index 1cacdca..fa1e375 100644
> > --- a/src/lxc/stop.c
> > +++ b/src/lxc/stop.c
> > @@ -40,7 +40,7 @@
> >  
> >  lxc_log_define(lxc_stop, lxc);
> >  
> > -int lxc_stop(const char *name)
> > +int lxc_stop(const char *name, const char *lxcpath)
> >  {
> >  	struct lxc_command command = {
> >  		.request = { .type = LXC_COMMAND_STOP },
> > @@ -48,7 +48,7 @@ int lxc_stop(const char *name)
> >  
> >  	int ret, stopped = 0;
> >  
> > -	ret = lxc_command(name, &command,&stopped);
> > +	ret = lxc_command(name, &command,&stopped, lxcpath);
> >  	if (ret < 0 && stopped) {
> >  		INFO("'%s' is already stopped", name);
> >  		return 0;
> > 
> 
> 





More information about the lxc-devel mailing list