[lxc-devel] [PATCH] api: convert lxc_wait, lxc_freeze, and lxc_unfreeze

Dwight Engen dwight.engen at oracle.com
Wed Aug 21 22:50:51 UTC 2013


On Wed, 21 Aug 2013 16:53:52 -0500
Serge Hallyn <serge.hallyn at ubuntu.com> wrote:

> These are the last of the simpler conversions.  Start, execute,
> kill, info and attach remain to be done.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

Looks good to me

Acked-by: Dwight Engen <dwight.engen at oracle.com>

> ---
>  src/lxc/lxc_freeze.c   | 26 ++++++++++++++++++++++----
>  src/lxc/lxc_unfreeze.c | 26 ++++++++++++++++++++++----
>  src/lxc/lxc_wait.c     | 15 ++++++++++++---
>  3 files changed, 56 insertions(+), 11 deletions(-)
> 
> diff --git a/src/lxc/lxc_freeze.c b/src/lxc/lxc_freeze.c
> index 3bd5e28..9628e78 100644
> --- a/src/lxc/lxc_freeze.c
> +++ b/src/lxc/lxc_freeze.c
> @@ -28,9 +28,12 @@
>  
>  #include <lxc/lxc.h>
>  #include <lxc/log.h>
> +#include <lxc/lxccontainer.h>
>  
>  #include "arguments.h"
>  
> +lxc_log_define(lxc_freeze_ui, lxc_cgroup);
> +
>  static const struct option my_longopts[] = {
>  	LXC_COMMON_OPTIONS
>  };
> @@ -51,13 +54,28 @@ Options :\n\
>  
>  int main(int argc, char *argv[])
>  {
> +	struct lxc_container *c;
> +
>  	if (lxc_arguments_parse(&my_args, argc, argv))
> -		return -1;
> +		exit(1);
>  
>  	if (lxc_log_init(my_args.name, my_args.log_file,
> my_args.log_priority, my_args.progname, my_args.quiet,
> my_args.lxcpath[0]))
> -		return -1;
> +		exit(1);
>  
> -	return lxc_freeze(my_args.name, my_args.lxcpath[0]);
> -}
> +	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
> +	if (!c) {
> +		ERROR("No such container: %s:%s",
> my_args.lxcpath[0], my_args.name);
> +		exit(1);
> +	}
>  
> +	if (!c->freeze(c)) {
> +		ERROR("Failed to freeze %s:%s", my_args.lxcpath[0],
> my_args.name);
> +		lxc_container_put(c);
> +		exit(1);
> +	}
> +
> +	lxc_container_put(c);
> +
> +	return 0;
> +}
> diff --git a/src/lxc/lxc_unfreeze.c b/src/lxc/lxc_unfreeze.c
> index 095f290..840467a 100644
> --- a/src/lxc/lxc_unfreeze.c
> +++ b/src/lxc/lxc_unfreeze.c
> @@ -27,9 +27,12 @@
>  
>  #include <lxc/lxc.h>
>  #include <lxc/log.h>
> +#include <lxc/lxccontainer.h>
>  
>  #include "arguments.h"
>  
> +lxc_log_define(lxc_unfreeze_ui, lxc_cgroup);
> +
>  static const struct option my_longopts[] = {
>  	LXC_COMMON_OPTIONS
>  };
> @@ -50,13 +53,28 @@ Options :\n\
>  
>  int main(int argc, char *argv[])
>  {
> +	struct lxc_container *c;
> +
>  	if (lxc_arguments_parse(&my_args, argc, argv))
> -		return -1;
> +		exit(1);
>  
>  	if (lxc_log_init(my_args.name, my_args.log_file,
> my_args.log_priority, my_args.progname, my_args.quiet,
> my_args.lxcpath[0]))
> -		return -1;
> +		exit(1);
>  
> -	return lxc_unfreeze(my_args.name, my_args.lxcpath[0]);
> -}
> +	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
> +	if (!c) {
> +		ERROR("No such container: %s:%s",
> my_args.lxcpath[0], my_args.name);
> +		exit(1);
> +	}
>  
> +	if (!c->unfreeze(c)) {
> +		ERROR("Failed to unfreeze %s:%s",
> my_args.lxcpath[0], my_args.name);
> +		lxc_container_put(c);
> +		exit(1);
> +	}
> +
> +	lxc_container_put(c);
> +
> +	return 0;
> +}
> diff --git a/src/lxc/lxc_wait.c b/src/lxc/lxc_wait.c
> index f1a065c..afbb81a 100644
> --- a/src/lxc/lxc_wait.c
> +++ b/src/lxc/lxc_wait.c
> @@ -30,7 +30,7 @@
>  
>  #include <lxc/lxc.h>
>  #include <lxc/log.h>
> -#include <lxc/monitor.h>
> +#include <lxc/lxccontainer.h>
>  #include "arguments.h"
>  
>  lxc_log_define(lxc_wait_ui, lxc_monitor);
> @@ -80,6 +80,8 @@ Options :\n\
>  
>  int main(int argc, char *argv[])
>  {
> +	struct lxc_container *c;
> +
>  	if (lxc_arguments_parse(&my_args, argc, argv))
>  		return -1;
>  
> @@ -87,6 +89,13 @@ int main(int argc, char *argv[])
>  			 my_args.progname, my_args.quiet,
> my_args.lxcpath[0])) return -1;
>  
> -	return lxc_wait(strdup(my_args.name), my_args.states,
> my_args.timeout,
> -			my_args.lxcpath[0]);
> +	c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
> +	if (!c)
> +		return -1;
> +
> +	if (!c->wait(c, my_args.states, my_args.timeout)) {
> +		lxc_container_put(c);
> +		return -1;
> +	}
> +	return 0;
>  }





More information about the lxc-devel mailing list