1
0
Fork 0

Report errors in subprocesses

This commit is contained in:
Nicolas Jeannerod 2025-02-26 13:07:34 +01:00
parent 0c75a4053e
commit cbed66c934
Signed by untrusted user: Niols
GPG key ID: 35DB9EC8886E1CB8
2 changed files with 31 additions and 2 deletions

View file

@ -366,7 +366,20 @@ provision_vm () (
for vm_name in $vm_names; do
provision_vm "$vm_name" &
done
wait
nb_errors=0
while :; do
wait -n && :
case $? in
0) ;;
127) break ;;
*) nb_errors=$((nb_errors + 1)) ;;
esac
done
if [ "$nb_errors" != 0 ]; then
die 'encountered %d errors while provisioning VMs%s.' "$nb_errors" "$vm_names"
fi
printf 'done provisioning VMs%s.\n' "$vm_names"
@ -374,3 +387,4 @@ printf 'done provisioning VMs%s.\n' "$vm_names"
## Cleanup
rm -Rf $tmpdir
exit 0

View file

@ -112,6 +112,7 @@ proxmox () {
}
## Way to inject different behaviour on unexpected status.
# shellcheck disable=SC2317
default_proxmox_sync_unexpected_status_handler () {
die "unexpected status: '%s'" "$1"
}
@ -194,6 +195,7 @@ stop_vm () {
################################################################################
## Delete VM
# shellcheck disable=SC2317
proxmox_sync_unexpected_status_handler_ignore_null () {
case $1 in
null)
@ -233,7 +235,19 @@ remove_vm () (
for vm_id_or_name in $vm_ids_or_names; do
remove_vm "$vm_id_or_name" &
done
wait
nb_errors=0
while :; do
wait -n && :
case $? in
0) ;;
127) break ;;
*) nb_errors=$((nb_errors + 1)) ;;
esac
done
if [ "$nb_errors" != 0 ]; then
die 'encountered %d errors while removing VMs%s.' "$nb_errors" "$vm_ids_or_names"
fi
printf 'done removing VMs%s.\n' "$vm_ids_or_names"
@ -241,3 +255,4 @@ printf 'done removing VMs%s.\n' "$vm_ids_or_names"
## Cleanup
rm -Rf $tmpdir
exit 0