Mercurial > archived > louis > perso > liblxcstats
view tests/span_containers.c @ 7:8339ab15527d
Add running/stopped containers global statistics and refactor some things
author | Louis Opter <louis@dotcloud.com> |
---|---|
date | Sat, 01 Jan 2011 17:46:40 +0100 |
parents | 6ce4443e7545 |
children |
line wrap: on
line source
#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; struct lxcst_globals globals; 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); lxcst_globals_statistics(&globals); if (globals.running_containers != n) errx(EXIT_FAILURE, "running_containers != spanned containers"); printf("%s: %d running containers, %d stopped containers.\n", *argv, globals.running_containers, globals.stopped_containers); return (EXIT_SUCCESS); (void)argc; }