[pve-devel] [PATCH common v2 2/3] daemon: refactor and cleanup

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Nov 10 12:09:28 CET 2017


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

changes v1 -> v2:
* use just an short foreach instead of map, as map is overkill here

 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);
     }
 
-- 
2.11.0





More information about the pve-devel mailing list