diff tests/span_containers.c @ 0:6ce4443e7545

Add the draft of an API to collect statistics on LXC
author Louis Opter <kalessin@kalessin.fr>
date Wed, 29 Dec 2010 23:28:14 +0100
parents
children 8339ab15527d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/span_containers.c	Wed Dec 29 23:28:14 2010 +0100
@@ -0,0 +1,40 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "lxcstats.h"
+
+unsigned int n = 0;
+
+int
+cb(void *ctx, const struct lxcst *container)
+{
+    if (ctx)
+        errx(EXIT_FAILURE, "ctx must be NULL");
+
+    if (!container)
+        errx(EXIT_FAILURE, "container must not be NULL");
+
+    ++n;
+
+    return (0); /* continue */
+}
+
+int
+main(int argc, char *argv[])
+{
+    lxcst_handle   *hdl;
+
+    hdl = lxcst_open();
+    if (!hdl)
+        err(EXIT_FAILURE, "lxcst_open failed");
+
+    lxcst_span_containers(hdl, &cb, NULL);
+
+    lxcst_close(hdl);
+
+    printf("%s: spanned %d containers.\n", *argv, n);
+
+    return (EXIT_SUCCESS);
+    (void)argc;
+}