sometimes we may want to call the hookscript with additional parameters in some phases, e.g. we want to call it for each pci device that was prepared before starting with the correct uuid or pci id.
Add these new parameters to the environment instead of the positional parameters of the hookscript, since that is more future proof and we get a key/value pair instead of just the position. Use the prefix 'PVE_HOOK_' so they're always in a separate namespace. Signed-off-by: Dominik Csapak <[email protected]> --- src/PVE/GuestHelpers.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm index f8d112b..1536259 100644 --- a/src/PVE/GuestHelpers.pm +++ b/src/PVE/GuestHelpers.pm @@ -115,14 +115,23 @@ sub check_hookscript { } sub exec_hookscript { - my ($conf, $vmid, $phase, $stop_on_error) = @_; + my ($conf, $vmid, $phase, $stop_on_error, $params) = @_; return if !$conf->{hookscript}; + $params //= {}; + eval { my $hookscript = check_hookscript($conf->{hookscript}); die $@ if $@; + local %ENV; + + for my $key (keys $params->%*) { + my $new_key = "PVE_HOOK_" . uc($key); + $ENV{$new_key} = $params->{$key}; + } + PVE::Tools::run_command([$hookscript, $vmid, $phase]); }; if (my $err = $@) { -- 2.47.3
