]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc_info.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <sys/types.h>
34 #include "arguments.h"
38 static char *test_state
= NULL
;
39 static char **key
= NULL
;
42 static int my_parser(struct lxc_arguments
* args
, int c
, char* arg
)
46 key
= realloc(key
, keys
+1 * sizeof(key
[0]));
50 case 's': state
= true; break;
51 case 'p': pid
= true; break;
52 case 't': test_state
= arg
; break;
57 static const struct option my_longopts
[] = {
58 {"config", required_argument
, 0, 'c'},
59 {"state", no_argument
, 0, 's'},
60 {"pid", no_argument
, 0, 'p'},
61 {"state-is", required_argument
, 0, 't'},
65 static struct lxc_arguments my_args
= {
66 .progname
= "lxc-info",
70 lxc-info display some information about a container with the identifier NAME\n\
73 -n, --name=NAME NAME for name of the container\n\
74 -c, --config=KEY show configuration variable KEY from running container\n\
75 -p, --pid shows the process id of the init container\n\
76 -s, --state shows the state of the container\n\
77 -t, --state-is=STATE test if current state is STATE\n\
78 returns success if it matches, false otherwise\n",
79 .options
= my_longopts
,
84 int main(int argc
, char *argv
[])
88 ret
= lxc_arguments_parse(&my_args
, argc
, argv
);
92 if (lxc_log_init(my_args
.name
, my_args
.log_file
, my_args
.log_priority
,
93 my_args
.progname
, my_args
.quiet
, my_args
.lxcpath
[0]))
96 if (!state
&& !pid
&& keys
<= 0)
99 if (state
|| test_state
) {
100 ret
= lxc_getstate(my_args
.name
, my_args
.lxcpath
[0]);
104 return strcmp(lxc_state2str(ret
), test_state
) != 0;
106 printf("state:%10s\n", lxc_state2str(ret
));
112 initpid
= lxc_cmd_get_init_pid(my_args
.name
, my_args
.lxcpath
[0]);
114 printf("pid:%10d\n", initpid
);
117 for(i
= 0; i
< keys
; i
++) {
120 val
= lxc_cmd_get_config_item(my_args
.name
, key
[i
], my_args
.lxcpath
[0]);
122 printf("%s = %s\n", key
[i
], val
);
125 fprintf(stderr
, "%s unset or invalid\n", key
[i
]);