From 0da5a3e43b1659431a6e0fa4e38583741d27dbbc Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 10 Nov 2017 12:09:28 +0100 Subject: [PATCH] daemon: refactor and cleanup Signed-off-by: Thomas Lamprecht --- 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 d438d27..55a03fc 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; @@ -289,11 +285,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; - } - } + $self->{old_workers}->{$_} = 1 foreach (split(':', $wpids)); } } @@ -503,8 +495,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); }