[pve-devel] [PATCH common 2/3] daemon: refactor and cleanup
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Nov 9 14:56:28 CET 2017
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/Daemon.pm | 15 +++------------
1 file changed, 3 insertions(+), 12 deletions(-)
diff --git a/src/PVE/Daemon.pm b/src/PVE/Daemon.pm
index a6b58d1..cc2cfa0 100644
--- a/src/PVE/Daemon.pm
+++ b/src/PVE/Daemon.pm
@@ -146,11 +146,7 @@ my $start_workers = sub {
return if $self->{terminate};
- my $count = 0;
- foreach my $cpid (keys %{$self->{workers}}) {
- $count++;
- }
-
+ my $count = scalar keys %{$self->{workers}};
my $need = $self->{max_workers} - $count;
return if $need <= 0;
@@ -297,11 +293,7 @@ sub setup {
if ($restart && $self->{max_workers}) {
if (my $wpids = $ENV{PVE_DAEMON_WORKER_PIDS}) {
- foreach my $pid (split(':', $wpids)) {
- if ($pid =~ m/^(\d+)$/) {
- $self->{old_workers}->{$1} = 1;
- }
- }
+ map { $self->{old_workers}->{$_} = 1 } split(':', $wpids);
}
}
@@ -511,8 +503,7 @@ sub restart_daemon {
}
if ($self->{max_workers}) {
- my @workers = keys %{$self->{workers}};
- push @workers, keys %{$self->{old_workers}};
+ my @workers = keys %{$self->{workers}}, keys %{$self->{old_workers}};
$ENV{PVE_DAEMON_WORKER_PIDS} = join(':', @workers);
}
--
2.11.0
More information about the pve-devel
mailing list