[lxc-devel] [PATCH] lxc_cgroup: convert to using API
Serge Hallyn
serge.hallyn at ubuntu.com
Wed Aug 21 19:35:28 UTC 2013
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/lxc_cgroup.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 094686d..7f6eb63 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -29,6 +29,7 @@
#include <lxc/lxc.h>
#include <lxc/log.h>
+#include <lxc/lxccontainer.h>
#include "arguments.h"
lxc_log_define(lxc_cgroup_ui, lxc_cgroup);
@@ -64,6 +65,7 @@ Options :\n\
int main(int argc, char *argv[])
{
char *state_object = NULL, *value = NULL;
+ struct lxc_container *c;
if (lxc_arguments_parse(&my_args, argc, argv))
return -1;
@@ -74,29 +76,36 @@ int main(int argc, char *argv[])
state_object = my_args.argv[0];
- if ((argc) > 1)
- value = my_args.argv[1];
+ c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
+ if (!c)
+ return -1;
+ if (!c->is_running(c)) {
+ ERROR("'%s:%s' is not running", my_args.lxcpath[0], my_args.name);
+ lxc_container_put(c);
+ return -1;
+ }
- if (value) {
- if (lxc_cgroup_set(my_args.name, state_object, value, my_args.lxcpath[0])) {
+ if ((my_args.argc) > 1) {
+ value = my_args.argv[1];
+ if (!c->set_cgroup_item(c, state_object, value)) {
ERROR("failed to assign '%s' value to '%s' for '%s'",
value, state_object, my_args.name);
+ lxc_container_put(c);
return -1;
}
} else {
- const unsigned long len = 4096;
- int ret;
+ int len = 4096;
char buffer[len];
-
- ret = lxc_cgroup_get(my_args.name, state_object, buffer, len, my_args.lxcpath[0]);
+ int ret = c->get_cgroup_item(c, state_object, buffer, len);
if (ret < 0) {
- ERROR("failed to retrieve value of '%s' for '%s'",
- state_object, my_args.name);
+ ERROR("failed to retrieve value of '%s' for '%s:%s'",
+ state_object, my_args.lxcpath[0], my_args.name);
+ lxc_container_put(c);
return -1;
}
-
printf("%*s", ret, buffer);
}
+ lxc_container_put(c);
return 0;
}
--
1.8.3.2
More information about the lxc-devel
mailing list