Fix a bug where errors that where not created using log_error where
not registered to the monitoring subsystem.
log_error() {
ERRORS+=("$*")
echo "ERROR: $@" | tee $RESULT >&2
log_error() {
ERRORS+=("$*")
echo "ERROR: $@" | tee $RESULT >&2
+
+ # Use return instead of exit. The set -x options will terminate the script
+ # but will also trigger ERR traps if defined.
+ return 1
if [ $rc -eq 0 ]; then
report_task_end
if [ $rc -eq 0 ]; then
report_task_end
+# Enable errtrace to make functions inherit the ERR trap
+set -o errtrace
+
+trap report_error ERR
+
if grep snf_image_activate_helper /proc/cmdline > /dev/null; then
# terminate helper vm when the script exits
add_cleanup system_poweroff
if grep snf_image_activate_helper /proc/cmdline > /dev/null; then
# terminate helper vm when the script exits
add_cleanup system_poweroff
log_error "run-parts program is missing from the system"
fi
log_error "run-parts program is missing from the system"
fi
-# If something goes wrong with the tasks, try to umount the target filesystem
-# in case it is left mounted...
-trap '{ umount "$target"; }' ERR
if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
if [ -z "$SNF_IMAGE_PROPERTY_EXCLUDE_ALL_TASKS" ]; then
log_error "Supported values for OSFAMILY property are: linux|windows"
fi
log_error "Supported values for OSFAMILY property are: linux|windows"
fi
+ # If something goes wrong with the tasks, try to umount the target
+ # file system in case it is left mounted...
+ trap '{ umount "$target"; }' ERR
+
# Redirect standard error to standard output,
# prepend a timestamp before each line of output.
echo "Execute all snf-image tasks...."
# Redirect standard error to standard output,
# prepend a timestamp before each line of output.
echo "Execute all snf-image tasks...."
while IFS= read -r line; do
echo $($DATE +%Y:%m:%d-%H:%M:%S.%N) "$line"
done
while IFS= read -r line; do
echo $($DATE +%Y:%m:%d-%H:%M:%S.%N) "$line"
done
+
+ trap report_error ERR
-# Disable the trap. If code reaches here, the filesystem is unmounted.
-trap - ERR
echo "SUCCESS" > "$RESULT"
echo "SUCCESS" > "$RESULT"