From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id E3C4F1FF09F for ; Thu, 03 Sep 2026 10:52:59 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 456D82157F; Thu, 03 Sep 2026 10:52:59 +0200 (CEST) Content-Type: text/plain; charset=UTF-8 Date: Thu, 03 Sep 2026 10:52:52 +0200 Message-Id: Subject: Re: [PATCH guest-common v4 1/7] helpers: exec hookscript: add optional parameters From: "Jakob Klocker" To: "Dominik Csapak" , Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 X-Mailer: aerc 0.20.0 References: <20260825135502.3971930-1-d.csapak@proxmox.com> <20260825135502.3971930-2-d.csapak@proxmox.com> In-Reply-To: <20260825135502.3971930-2-d.csapak@proxmox.com> X-TUID: 3Gk/q3uQAm8i X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1788425570220 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.676 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 5PNEWIL26FNRWV6R2XOQPPHQUBIUIWBZ X-Message-ID-Hash: 5PNEWIL26FNRWV6R2XOQPPHQUBIUIWBZ X-MailFrom: j.klocker@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: style-nit inline. On Tue Aug 25, 2026 at 3:54 PM CEST, Dominik Csapak wrote: > 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 > --- > src/PVE/GuestHelpers.pm | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/src/PVE/GuestHelpers.pm b/src/PVE/GuestHelpers.pm > index f8d112b..6899b05 100644 > --- a/src/PVE/GuestHelpers.pm > +++ b/src/PVE/GuestHelpers.pm > @@ -115,14 +115,24 @@ sub check_hookscript { > } > =20 > sub exec_hookscript { > - my ($conf, $vmid, $phase, $stop_on_error) =3D @_; > + my ($conf, $vmid, $phase, $stop_on_error, $params) =3D @_; > =20 > return if !$conf->{hookscript}; > =20 > + $params //=3D {}; According to the Perl style guide [0],=20 `$params =3D {} if !defined($params);` is prefered over the `//=3D` syntax. Since I keep seeing this "old" syntax in new patches, I'm not sure if this is strictly lived though. [0] https://pve.proxmox.com/wiki/Perl_Style_Guide#Perl_syntax_choices > + > eval { > my $hookscript =3D check_hookscript($conf->{hookscript}); > die $@ if $@; > =20 > + # copy EVN before adding to it misspelled `ENV` in the comment. Might also be good adding why we're making a copy, instead of commenting what we're doing > + local %ENV =3D (%ENV); > + > + for my $key (keys $params->%*) { > + my $new_key =3D "PVE_HOOK_" . uc($key); > + $ENV{$new_key} =3D $params->{$key}; > + } > + > PVE::Tools::run_command([$hookscript, $vmid, $phase]); > }; > if (my $err =3D $@) {