[lxc-devel] [PATCH 2/3] lxc_stop: use the api
Serge Hallyn
serge.hallyn at ubuntu.com
Fri May 17 19:17:58 UTC 2013
Also if the container is not running, return -2. Currently
lxc-stop will return 0, so you cannot tell the difference
between successfull stopping and noop.
The main point of this is to have our tools using the api as
an example to others of how to use it.
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/lxc_stop.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c
index d7c7283..5e035b0 100644
--- a/src/lxc/lxc_stop.c
+++ b/src/lxc/lxc_stop.c
@@ -28,6 +28,7 @@
#include <lxc/lxc.h>
#include <lxc/log.h>
+#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "utils.h"
@@ -51,6 +52,9 @@ Options :\n\
int main(int argc, char *argv[])
{
+ struct lxc_container *c;
+ int ret = -1;
+
if (lxc_arguments_parse(&my_args, argc, argv))
return -1;
@@ -58,5 +62,20 @@ int main(int argc, char *argv[])
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return -1;
- return lxc_stop(my_args.name, my_args.lxcpath[0]);
+ c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
+ if (!c) {
+ fprintf(stderr, "Error opening container\n");
+ goto out;
+ }
+
+ if (!c->is_running(c)) {
+ fprintf(stderr, "%s is not running\n", c->name);
+ ret = -2;
+ goto out;
+ }
+
+ ret = c->stop(c) ? 0 : -1;
+out:
+ lxc_container_put(c);
+ return ret;
}
--
1.8.1.2
More information about the lxc-devel
mailing list