[pmg-devel] [PATCH pmg-api] fix #4815: pmgsh: declare rpcenv on top

Stoiko Ivanov s.ivanov at proxmox.com
Mon Jul 3 10:48:01 CEST 2023


and drop duplicate setup_default_cli_env and initlog invocation

Fixes: 1583283557956a431c4afe86d243c6fbc177034b
Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
quickly tested on my box pmgsh works and sbuild works as well with
the patch

 src/bin/pmgsh | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/bin/pmgsh b/src/bin/pmgsh
index f9816cd..475e886 100755
--- a/src/bin/pmgsh
+++ b/src/bin/pmgsh
@@ -37,6 +37,8 @@ sub print_usage {
 my $disable_proxy = 0;
 my $opt_nooutput = 0;
 
+my $rpcenv;
+
 my $cmd = shift;
 
 my $optmatch;
@@ -62,6 +64,7 @@ if ($cmd) {
 	exit 0;
     } elsif ($cmd =~ /^(?:ls|get|create|set|delete|help)$/) {
 	PMG::RESTEnvironment->setup_default_cli_env(); # only set up once actually required
+	$rpcenv = PMG::RESTEnvironment->get();
 	initlog($ENV{PVE_LOG_ID} || 'pmgsh');
 	pmg_command([ $cmd, @ARGV],  $opt_nooutput);
 	exit(0);
@@ -76,11 +79,6 @@ if (scalar (@ARGV) != 0) {
     exit(-1);
 }
 
-# only set up once actually required allows calling verifyapi in restriced clean sbuild env
-PMG::RESTEnvironment->setup_default_cli_env();
-my $rpcenv = PMG::RESTEnvironment->get();
-initlog($ENV{PVE_LOG_ID} || 'pmgsh');
-
 print "entering PMG shell - type 'help' for help\n";
 
 my $term = new Term::ReadLine('pmgsh');
-- 
2.39.2





More information about the pmg-devel mailing list