diff --git a/plugins/lxc/README b/plugins/lxc/README index a437d22f..941ff402 100644 --- a/plugins/lxc/README +++ b/plugins/lxc/README @@ -6,4 +6,4 @@ Tested on Debian buster and Debian jessie. See the individual files for copyright and installation/configuration information. -This is version 1.0 by schaefer@alphanet.ch +This is version 1.1 by schaefer@alphanet.ch diff --git a/plugins/lxc/lxc-lib b/plugins/lxc/lxc-lib index 577cc70d..a88e9528 100644 --- a/plugins/lxc/lxc-lib +++ b/plugins/lxc/lxc-lib @@ -40,28 +40,40 @@ function active_guests { } function lxc_cgroup { - # lxc3 + # lxc3 (lxc < 3: may output some warnings if there is cruft in your config dir) lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' - - # lxc < 3 -# lxc-cgroup $* } function lxc_clean_fieldname { - # workaround for bug leaving out the first number - echo $(clean_fieldname ${1::1}$1) + # clean_fieldname should be used on the whole identifier, not just the + # lxc instance ID, because if it is only numeric, the first digit will + # be replaced with a "_"; this is a work-around + case "${1::1}" in + [0-9]) echo $(clean_fieldname ${1::1}$1);; # 104 -> __104 + *) echo $(clean_fieldname $1);; + esac } function lxc_netdev { local g=$1 dev if [ -f $lxcpath/$g/config ]; then - # lxc3 - egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' - - # lxc < 3 -# egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' + # lxc 3 vs < 3 + egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null | awk '{print $NF;}' \ + || egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' else echo unknown fi } + +# BUGS +# - I don't think this is enough or even appropriate +function lxc_autoconf { + if [ -r /proc/stat ]; then + echo yes + exit 0 + else + echo "no (no /proc/stat)" + exit 0 + fi +} diff --git a/plugins/lxc/lxc_cpu b/plugins/lxc/lxc_cpu index 2f76ff85..f501cad2 100755 --- a/plugins/lxc/lxc_cpu +++ b/plugins/lxc/lxc_cpu @@ -41,13 +41,7 @@ or GPLv3 license, at your option active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_cpu_time b/plugins/lxc/lxc_cpu_time index 8730a5a9..c483a916 100755 --- a/plugins/lxc/lxc_cpu_time +++ b/plugins/lxc/lxc_cpu_time @@ -41,13 +41,7 @@ or GPLv3 license, at your option active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_logins b/plugins/lxc/lxc_logins index d1fc3257..014aec33 100755 --- a/plugins/lxc/lxc_logins +++ b/plugins/lxc/lxc_logins @@ -38,13 +38,7 @@ GPLv3 active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_proc b/plugins/lxc/lxc_proc index e91274c9..f5c83704 100755 --- a/plugins/lxc/lxc_proc +++ b/plugins/lxc/lxc_proc @@ -77,13 +77,7 @@ count_processes () { } if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_ram b/plugins/lxc/lxc_ram index 68e80038..bf6a4134 100755 --- a/plugins/lxc/lxc_ram +++ b/plugins/lxc/lxc_ram @@ -41,13 +41,7 @@ or GPLv3 license, at your option active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then