From 84c53fc120694c4b209681401ef50a058b9a75fb Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Mon, 23 Oct 2023 10:41:46 +0200 Subject: [PATCH] hook-helper: repurpose third arg for skip options now that qemu-user info does not need to be propagated anymore (was only needed for proot) --- mmdebstrap | 17 +++++++++++++++-- tests/special-hooks-using-helpers | 2 +- tests/special-hooks-using-helpers-and-env-vars | 4 ++-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mmdebstrap b/mmdebstrap index c1a41de..992e4f4 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -1755,7 +1755,8 @@ sub run_hooks { # does for python my @args = shellwords $script; hookhelper($options->{root}, $options->{mode}, $name, - $options->{qemu}, $verbosity_level, @args); + (join ',', @{ $options->{skip} }), + $verbosity_level, @args); exit 0; } waitpid($pid, 0); @@ -3356,8 +3357,20 @@ sub pivot_root { } sub hookhelper { - my ($root, $mode, $hook, $qemu, $verbosity, $command, @args) = @_; + my ($root, $mode, $hook, $skipopt, $verbosity, $command, @args) = @_; $verbosity_level = $verbosity; + my @skipopts = (); + if (length $skipopt) { + for my $skip (split /[,\s]+/, $skipopt) { + # strip leading and trailing whitespace + $skip =~ s/^\s+|\s+$//g; + # skip if the remainder is an empty string + if ($skip eq '') { + next; + } + push @skipopts, $skip; + } + } # we put everything in an eval block because that way we can easily handle # errors without goto labels or much code duplication: the error handler # has to send an "error" message to the other side diff --git a/tests/special-hooks-using-helpers b/tests/special-hooks-using-helpers index a64eaf8..a211746 100644 --- a/tests/special-hooks-using-helpers +++ b/tests/special-hooks-using-helpers @@ -8,7 +8,7 @@ mkdir /tmp/root/real run_testA() { echo content > /tmp/foo # shellcheck disable=SC2094 - { { { {{ CMD }} --hook-helper /tmp/root root setup env 1 upload /tmp/foo "$1" < /tmp/myfifo 3>&-; echo $? >&3; printf "\\000\\000adios"; + { { { {{ CMD }} --hook-helper /tmp/root root setup '' 1 upload /tmp/foo "$1" < /tmp/myfifo 3>&-; echo $? >&3; printf "\\000\\000adios"; } | {{ CMD }} --hook-listener 1 3>&- >/tmp/myfifo; echo $?; } 3>&1; } | { read -r xs1; [ "$xs1" -eq 0 ]; read -r xs2; [ "$xs2" -eq 0 ]; } echo content | diff -u - /tmp/root/real/foo diff --git a/tests/special-hooks-using-helpers-and-env-vars b/tests/special-hooks-using-helpers-and-env-vars index a3ba90e..7a1ffeb 100644 --- a/tests/special-hooks-using-helpers-and-env-vars +++ b/tests/special-hooks-using-helpers-and-env-vars @@ -8,12 +8,12 @@ echo "MMDEBSTRAP_APT_CONFIG $MMDEBSTRAP_APT_CONFIG" echo "$MMDEBSTRAP_HOOK" >> /tmp/hooks [ "$MMDEBSTRAP_MODE" = "root" ] echo test-content $MMDEBSTRAP_HOOK > test -{{ CMD }} --hook-helper "$1" "$MMDEBSTRAP_MODE" "$MMDEBSTRAP_HOOK" env 1 upload test /test <&$MMDEBSTRAP_HOOKSOCK >&$MMDEBSTRAP_HOOKSOCK +{{ CMD }} --hook-helper "$1" "$MMDEBSTRAP_MODE" "$MMDEBSTRAP_HOOK" '' 1 upload test /test <&$MMDEBSTRAP_HOOKSOCK >&$MMDEBSTRAP_HOOKSOCK rm test echo "content inside chroot:" cat "$1/test" [ "test-content $MMDEBSTRAP_HOOK" = "$(cat "$1/test")" ] -{{ CMD }} --hook-helper "$1" "$MMDEBSTRAP_MODE" "$MMDEBSTRAP_HOOK" env 1 download /test test <&$MMDEBSTRAP_HOOKSOCK >&$MMDEBSTRAP_HOOKSOCK +{{ CMD }} --hook-helper "$1" "$MMDEBSTRAP_MODE" "$MMDEBSTRAP_HOOK" '' 1 download /test test <&$MMDEBSTRAP_HOOKSOCK >&$MMDEBSTRAP_HOOKSOCK echo "content outside chroot:" cat test [ "test-content $MMDEBSTRAP_HOOK" = "$(cat test)" ]