mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-02 08:10:56 +00:00
introduce lxc_config
It's a tiny program (exported through the api) wrapping the util.c helpers for reading /etc/lxc/lxc.conf variables, and replaces the kludgy shell duplication in lxc.functions.in Changelog: Apr 30: address feedback from Dwight (exit error on failure, and use 'lxcpath' as name, not 'default_path'). Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com> Acked-by: Dwight Engen <dwight.engen@oracle.com>
This commit is contained in:
parent
1e1bb42a8f
commit
a8428dfa2c
@ -162,7 +162,8 @@ bin_PROGRAMS = \
|
||||
lxc-unfreeze \
|
||||
lxc-checkpoint \
|
||||
lxc-restart \
|
||||
lxc-kill
|
||||
lxc-kill \
|
||||
lxc-config
|
||||
|
||||
pkglibexec_PROGRAMS = \
|
||||
lxc-init
|
||||
@ -179,6 +180,7 @@ LDADD=liblxc.so @CAP_LIBS@ @APPARMOR_LIBS@ @SECCOMP_LIBS@
|
||||
lxc_attach_SOURCES = lxc_attach.c
|
||||
lxc_cgroup_SOURCES = lxc_cgroup.c
|
||||
lxc_checkpoint_SOURCES = lxc_checkpoint.c
|
||||
lxc_config_SOURCES = lxc_config.c
|
||||
lxc_console_SOURCES = lxc_console.c
|
||||
lxc_execute_SOURCES = lxc_execute.c
|
||||
lxc_freeze_SOURCES = lxc_freeze.c
|
||||
|
@ -25,33 +25,6 @@ bindir=@BINDIR@
|
||||
templatedir=@LXCTEMPLATEDIR@
|
||||
lxcinitdir=@LXCINITDIR@
|
||||
|
||||
get_default_lxcpath() {
|
||||
LXC_PATH=$(grep -v "^#" "$globalconf" 2>/dev/null | grep "[ \t]*lxcpath[ \t]*=") || true
|
||||
if [ -n "$LXC_PATH" ]; then
|
||||
echo $LXC_PATH | awk -F= '{ print $2 }'
|
||||
else
|
||||
echo @LXCPATH@
|
||||
fi
|
||||
}
|
||||
|
||||
get_default_vg() {
|
||||
LXC_VG=$(grep -v "^#" "$globalconf" 2>/dev/null | grep "[ \t]*lvm_vg[ \t]*=") || true
|
||||
if [ -n "$LXC_VG" ]; then
|
||||
echo $LXC_VG | awk -F= '{ print $2 }'
|
||||
else
|
||||
echo "lxc"
|
||||
fi
|
||||
}
|
||||
|
||||
get_default_zfsroot() {
|
||||
LXC_ZFSROOT=$(grep -v "^#" "$globalconf" 2>/dev/null | grep "[ \t]*zfsroot[ \t]*=") || true
|
||||
if [ -n "$LXC_ZFSROOT" ]; then
|
||||
echo $LXC_ZFSROOT | awk -F= '{ print $2 }'
|
||||
else
|
||||
echo "tank/lxc"
|
||||
fi
|
||||
}
|
||||
|
||||
lxc_path=`get_default_lxcpath`
|
||||
lxc_vg=`get_default_vg`
|
||||
lxc_zfsroot=`get_default_zfsroot`
|
||||
lxc_path=`lxc-config default_path`
|
||||
lxc_vg=`lxc-config lvm_vg`
|
||||
lxc_zfsroot=`lxc-config zfsroot`
|
||||
|
50
src/lxc/lxc_config.c
Normal file
50
src/lxc/lxc_config.c
Normal file
@ -0,0 +1,50 @@
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
#include "lxccontainer.h"
|
||||
|
||||
struct lxc_config_items {
|
||||
char *name;
|
||||
const char *(*fn)(void);
|
||||
};
|
||||
|
||||
struct lxc_config_items items[] =
|
||||
{
|
||||
{ .name = "lxcpath", .fn = &lxc_get_default_config_path, },
|
||||
{ .name = "lvm_vg", .fn = &lxc_get_default_lvm_vg, },
|
||||
{ .name = "zfsroot", .fn = &lxc_get_default_zfs_root, },
|
||||
{ .name = NULL, },
|
||||
};
|
||||
|
||||
void usage(char *me)
|
||||
{
|
||||
printf("Usage: %s -l: list all available configuration items\n", me);
|
||||
printf(" %s item: print configuration item\n", me);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void list_config_items(void)
|
||||
{
|
||||
struct lxc_config_items *i;
|
||||
|
||||
for (i = &items[0]; i->name; i++)
|
||||
printf("%s\n", i->name);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct lxc_config_items *i;
|
||||
|
||||
if (argc < 2)
|
||||
usage(argv[0]);
|
||||
if (strcmp(argv[1], "-l") == 0)
|
||||
list_config_items();
|
||||
for (i = &items[0]; i->name; i++) {
|
||||
if (strcmp(argv[1], i->name) == 0) {
|
||||
printf("%s\n", i->fn());
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
printf("Unknown configuration item: %s\n", argv[1]);
|
||||
exit(-1);
|
||||
}
|
@ -1009,6 +1009,16 @@ const char *lxc_get_default_config_path(void)
|
||||
return default_lxc_path();
|
||||
}
|
||||
|
||||
const char *lxc_get_default_lvm_vg(void)
|
||||
{
|
||||
return default_lvm_vg();
|
||||
}
|
||||
|
||||
const char *lxc_get_default_zfs_root(void)
|
||||
{
|
||||
return default_zfs_root();
|
||||
}
|
||||
|
||||
const char *lxc_get_version(void)
|
||||
{
|
||||
return lxc_version();
|
||||
|
@ -122,6 +122,8 @@ int lxc_container_get(struct lxc_container *c);
|
||||
int lxc_container_put(struct lxc_container *c);
|
||||
int lxc_get_wait_states(const char **states);
|
||||
const char *lxc_get_default_config_path(void);
|
||||
const char *lxc_get_default_lvm_vg(void);
|
||||
const char *lxc_get_default_zfs_root(void);
|
||||
const char *lxc_get_version(void);
|
||||
|
||||
#if 0
|
||||
|
Loading…
Reference in New Issue
Block a user