static bool state;
static bool pid;
+static char *test_state = NULL;
static int my_parser(struct lxc_arguments* args, int c, char* arg)
{
switch (c) {
case 's': state = true; break;
case 'p': pid = true; break;
+ case 't': test_state = arg; break;
}
return 0;
}
static const struct option my_longopts[] = {
{"state", no_argument, 0, 's'},
{"pid", no_argument, 0, 'p'},
+ {"state-is", required_argument, 0, 't'},
LXC_COMMON_OPTIONS,
};
lxc-info display some information about a container with the identifier NAME\n\
\n\
Options :\n\
- -n, --name=NAME NAME for name of the container\n\
- -s, --state shows the state of the container\n\
- -p, --pid shows the process id of the init container\n",
+ -n, --name=NAME NAME for name of the container\n\
+ -s, --state shows the state of the container\n\
+ -p, --pid shows the process id of the init container\n\
+ -t, --state-is=STATE test if current state is STATE\n\
+ returns success if it matches, false otherwise\n",
.options = my_longopts,
.parser = my_parser,
.checker = NULL,
if (!state && !pid)
state = pid = true;
- if (state) {
+ if (state || test_state) {
ret = lxc_getstate(my_args.name);
if (ret < 0)
return 1;
+ if (test_state)
+ return strcmp(lxc_state2str(ret), test_state) != 0;
printf("state:%10s\n", lxc_state2str(ret));
}