From 967e98230a988b0412a9d6c8178e0362853d91a6 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 11 Apr 2023 16:17:10 +0200 Subject: [PATCH] various perl critic fixes Signed-off-by: Thomas Lamprecht --- src/PVE/CpuSet.pm | 3 ++- src/PVE/Daemon.pm | 10 +++++----- src/PVE/RESTEnvironment.pm | 13 +++++-------- src/PVE/SectionConfig.pm | 2 +- src/PVE/Syscall.pm | 3 +++ 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/PVE/CpuSet.pm b/src/PVE/CpuSet.pm index 12bda2c..1292558 100644 --- a/src/PVE/CpuSet.pm +++ b/src/PVE/CpuSet.pm @@ -131,7 +131,8 @@ sub has { sub members { my ($self) = @_; - return sort { $a <=> $b } keys %{$self->{members}}; + my @sorted_members = sort { $a <=> $b } keys %{$self->{members}}; + return @sorted_members; } sub size { diff --git a/src/PVE/Daemon.pm b/src/PVE/Daemon.pm index 032cb27..63fd5ee 100644 --- a/src/PVE/Daemon.pm +++ b/src/PVE/Daemon.pm @@ -114,10 +114,10 @@ my $writepidfile = sub { my $pidfile = $self->{pidfile}; - die "can't open pid file '$pidfile' - $!\n" if !open (PIDFH, ">$pidfile"); + open (my $PID_FH, '>', "$pidfile") or die "can't open pid file '$pidfile' - $!\n"; - print PIDFH "$$\n"; - close (PIDFH); + print $PID_FH "$$\n"; + close ($PID_FH); }; my $server_cleanup = sub { @@ -310,8 +310,8 @@ my $server_run = sub { $self->init(); if (!$debug) { - open STDIN, '/dev/null' || die "can't write /dev/null"; + open STDIN, '<', '/dev/null' or die "can't read /dev/null - $!"; + open STDOUT, '>', '/dev/null' or die "can't write /dev/null - $!"; } if (!$self->{env_restart_pve_daemon} && !$debug) { diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm index 89def38..191c6eb 100644 --- a/src/PVE/RESTEnvironment.pm +++ b/src/PVE/RESTEnvironment.pm @@ -431,7 +431,7 @@ my $tee_worker = sub { }; local $SIG{PIPE} = sub { die "broken pipe\n"; }; - my $select = new IO::Select; + my $select = IO::Select->new(); my $fh = IO::Handle->new_from_fd($childfd, 'r'); $select->add($fh); @@ -509,7 +509,7 @@ sub fork_worker { my @psync = POSIX::pipe(); my @csync = POSIX::pipe(); - my @ctrlfd = POSIX::pipe() if $sync; + my @ctrlfd = $sync ? POSIX::pipe() : (); my $node = $self->{nodename}; @@ -571,8 +571,7 @@ sub fork_worker { close STDIN; POSIX::close(0) if $fd != 0; - die "unable to redirect STDIN - $!" - if !open(STDIN, "&", $outfh); + open(STDOUT, ">&", $outfh) or die "unable to redirect STDOUT - $!"; STDOUT->autoflush (1); @@ -594,8 +592,7 @@ sub fork_worker { close STDERR; POSIX::close(2) if $fd != 2; - die "unable to redirect STDERR - $!" - if !open(STDERR, ">&1"); + open(STDERR, '>&', '1') or die "unable to redirect STDERR - $!"; STDERR->autoflush(1); }; diff --git a/src/PVE/SectionConfig.pm b/src/PVE/SectionConfig.pm index e354655..f36cede 100644 --- a/src/PVE/SectionConfig.pm +++ b/src/PVE/SectionConfig.pm @@ -115,7 +115,7 @@ sub updateSchema { my $props = {}; - my $filter_type = $class->type() if $single_class; + my $filter_type = $single_class ? $class->type() : undef; foreach my $p (keys %$propertyList) { next if $p eq 'type'; diff --git a/src/PVE/Syscall.pm b/src/PVE/Syscall.pm index ee374d8..4c0b9cf 100644 --- a/src/PVE/Syscall.pm +++ b/src/PVE/Syscall.pm @@ -1,5 +1,8 @@ package PVE::Syscall; +use strict; +use warnings; + my %syscalls; my %fsmount_constants; BEGIN { -- 2.39.5