From: Dwight Engen Date: Mon, 1 Jul 2013 16:38:23 +0000 (-0400) Subject: allow lxc-info to get running container configuration X-Git-Tag: lxc-1.0.0.alpha1~1^2~141 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c631ea7c2906f41b23f5c8dcc9f6045078879db;p=thirdparty%2Flxc.git allow lxc-info to get running container configuration Signed-off-by: Dwight Engen Signed-off-by: Serge Hallyn --- diff --git a/doc/lxc-info.sgml.in b/doc/lxc-info.sgml.in index ba0a044d1..39cd4d172 100644 --- a/doc/lxc-info.sgml.in +++ b/doc/lxc-info.sgml.in @@ -48,9 +48,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA lxc-info -n name - -s - -p - -t state + -c KEY + -s + -p + -t state @@ -77,6 +78,18 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + + + + + Print a configuration key from the running container. This option + may be given mulitple times to print out multiple key = value pairs. + + + + @@ -135,6 +148,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + lxc-info -n foo -c lxc.network.0.veth.pair + + + prints the veth pair name of foo. + + + + diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c index f86626d97..b8d1c1873 100644 --- a/src/lxc/lxc_info.c +++ b/src/lxc/lxc_info.c @@ -36,10 +36,17 @@ static bool state; static bool pid; static char *test_state = NULL; +static char **key = NULL; +static int keys = 0; static int my_parser(struct lxc_arguments* args, int c, char* arg) { switch (c) { + case 'c': + key = realloc(key, keys+1 * sizeof(key[0])); + key[keys] = arg; + keys++; + break; case 's': state = true; break; case 'p': pid = true; break; case 't': test_state = arg; break; @@ -48,6 +55,7 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg) } static const struct option my_longopts[] = { + {"config", required_argument, 0, 'c'}, {"state", no_argument, 0, 's'}, {"pid", no_argument, 0, 'p'}, {"state-is", required_argument, 0, 't'}, @@ -63,8 +71,9 @@ 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\ + -c, --config=KEY show configuration variable KEY from running container\n\ -p, --pid shows the process id of the init container\n\ + -s, --state shows the state of the container\n\ -t, --state-is=STATE test if current state is STATE\n\ returns success if it matches, false otherwise\n", .options = my_longopts, @@ -74,7 +83,7 @@ Options :\n\ int main(int argc, char *argv[]) { - int ret; + int ret,i; ret = lxc_arguments_parse(&my_args, argc, argv); if (ret) @@ -84,7 +93,7 @@ int main(int argc, char *argv[]) my_args.progname, my_args.quiet, my_args.lxcpath[0])) return 1; - if (!state && !pid) + if (!state && !pid && keys <= 0) state = pid = true; if (state || test_state) { @@ -105,5 +114,17 @@ int main(int argc, char *argv[]) printf("pid:%10d\n", initpid); } + for(i = 0; i < keys; i++) { + char *val; + + val = lxc_cmd_get_config_item(my_args.name, key[i], my_args.lxcpath[0]); + if (val) { + printf("%s = %s\n", key[i], val); + free(val); + } else { + fprintf(stderr, "%s unset or invalid\n", key[i]); + } + } + return 0; }