diff options
author | Jonathan Bauer | 2018-04-20 14:29:06 +0200 |
---|---|---|
committer | Jonathan Bauer | 2018-04-20 14:29:06 +0200 |
commit | b22136caef5963c6ff20307536be96a31198506f (patch) | |
tree | 1ea3e02d1add3e77ff8550df767c8181b873caa3 /core/modules/vbox-src | |
parent | [vbox-src] validate downloaded xml file (diff) | |
download | mltk-b22136caef5963c6ff20307536be96a31198506f.tar.gz mltk-b22136caef5963c6ff20307536be96a31198506f.tar.xz mltk-b22136caef5963c6ff20307536be96a31198506f.zip |
[vbox-src] more error handling/logging
to make sure we have ways to debug if anything goes wrong once deployed
Diffstat (limited to 'core/modules/vbox-src')
-rwxr-xr-x | core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc | 48 |
1 files changed, 42 insertions, 6 deletions
diff --git a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc index f724bc25..2ff95bbf 100755 --- a/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc +++ b/core/modules/vbox-src/data/opt/openslx/vmchooser/plugins/virtualbox/includes/init_core.inc @@ -11,12 +11,20 @@ add_node() { if [ $# -lt 2 ]; then writelog "${FUNCNAME[0]} requires 2 or more args, $# given." - cleanexit 1 + return 1 fi local PARENT="$1" shift + if isempty PARENT; then + writelog "${FUNCNAME[0]} empty parent given!" + return 1 + fi local NODE="$1" shift + if isempty NODE; then + writelog "${FUNCNAME[0]} empty node given!" + return 1 + fi # if parent does not exists, create it aswell if ! node_exists "${PARENT}"; then add_node "${PARENT%/*}" "${PARENT##*/}" @@ -57,7 +65,11 @@ add_node() { set_attr() { if [ $# -ne 3 ]; then writelog "${FUNCNAME[0]} requires 3 args, $# given." - cleanexit 1 + return 1 + fi + if [ -z "$1" -o -z "$2" -o -z "$3" ]; then + writelog "${FUNCNAME[0]} empty arguments given: $@" + return 1 fi if ! node_exists "$1"; then add_node "${1%/*}" "${1##*/}" \ @@ -83,10 +95,15 @@ set_attr() { return $ret fi } +# del_node <node_xpath> del_node() { - if [ $# -ne 1]; then + if [ $# -ne 1 ]; then writelog "${FUNCNAME[0]} requires one arg, $# given." - cleanexit 1 + return 1 + fi + if [ -z "$1" ]; then + writelog "${FUNCNAME[0]} empty xpath expression given." + return 1 fi local ret xmlstarlet ed -L -N x="${VBOX_NAMESPACE}" \ @@ -98,23 +115,42 @@ del_node() { fi return $ret } +# attr_exists <node_xpath> <attr_name> attr_exists() { if [ $# -ne 2 ]; then writelog "${FUNCNAME[0]} requires node and attribute as args, $# given." - cleanexit 1 + return 1 + fi + if [ -z "$1" -o -z "$2" ]; then + writelog "${FUNCNAME[0]} some arguments were empty: $@" fi xmlstarlet -q sel -N x="${VBOX_NAMESPACE}" \ -t -v "$(print_namespaced "x" "$1")/@$2" \ "${TMPCONFIG}" + ret=$? + if [ "$ret" -ne 0 ]; then + writelog "${FUNCNAME[0]} failed with '$ret' for args: $@" + fi + return $ret } +# node_exists <node_xpath> node_exists() { if [ $# -ne 1 ]; then writelog "${FUNCNAME[0]} requires one arg, $# given." - cleanexit 1 + return 1 + fi + if [ -z "$1" ]; then + writelog "${FUNCNAME[0]} empty xpath expression given." + return 1 fi xmlstarlet -q sel -N x="${VBOX_NAMESPACE}" \ -t -c "$(print_namespaced "x" "$1")" \ "${TMPCONFIG}" + ret=$? + if [ "$ret" -ne 0 ]; then + writelog "${FUNCNAME[0]} failed with '$ret' for args: $@" + fi + return $ret } # adds the vbox namespace to an xpath expression using # the given placeholder for it. |