]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/tools/lxc_config.c
tree-wide: fix includes to fix bionic builds
[mirror_lxc.git] / src / lxc / tools / lxc_config.c
1 /* lxc_config
2 *
3 * Copyright © 2012 Serge Hallyn <serge.hallyn@ubuntu.com>.
4 * Copyright © 2012 Canonical Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef _GNU_SOURCE
22 #define _GNU_SOURCE 1
23 #endif
24 #include <stdio.h>
25 #include <string.h>
26
27 #include <lxc/lxccontainer.h>
28
29 #include "config.h"
30
31 struct lxc_config_items {
32 char *name;
33 };
34
35 static struct lxc_config_items items[] =
36 {
37 { .name = "lxc.default_config", },
38 { .name = "lxc.lxcpath", },
39 { .name = "lxc.bdev.lvm.vg", },
40 { .name = "lxc.bdev.lvm.thin_pool", },
41 { .name = "lxc.bdev.zfs.root", },
42 { .name = "lxc.cgroup.use", },
43 { .name = "lxc.cgroup.pattern", },
44 { .name = NULL, },
45 };
46
47 static void usage(char *me)
48 {
49 printf("Usage: %s -l: list all available configuration items\n", me);
50 printf(" %s item: print configuration item\n", me);
51 exit(EXIT_SUCCESS);
52 }
53
54 static void list_config_items(void)
55 {
56 struct lxc_config_items *i;
57
58 for (i = &items[0]; i->name; i++)
59 printf("%s\n", i->name);
60
61 exit(EXIT_SUCCESS);
62 }
63
64 int main(int argc, char *argv[])
65 {
66 struct lxc_config_items *i;
67 const char *value;
68
69 if (argc < 2 || strncmp(argv[1], "-h", strlen(argv[1])) == 0 ||
70 strncmp(argv[1], "--help", strlen(argv[1])) == 0)
71 usage(argv[0]);
72
73 if (strncmp(argv[1], "-l", strlen(argv[1])) == 0)
74 list_config_items();
75
76 for (i = &items[0]; i->name; i++) {
77 if (strncmp(argv[1], i->name, strlen(argv[1])) == 0) {
78 value = lxc_get_global_config_item(i->name);
79 if (value)
80 printf("%s\n", value);
81 else
82 printf("%s is not set.\n", argv[1]);
83
84 exit(EXIT_SUCCESS);
85 }
86 }
87
88 printf("Unknown configuration item: %s\n", argv[1]);
89 exit(EXIT_FAILURE);
90 }