[pve-devel] r5153 - pve-common/trunk

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Sep 15 09:40:45 CEST 2010


Author: dietmar
Date: 2010-09-15 07:40:45 +0000 (Wed, 15 Sep 2010)
New Revision: 5153

Modified:
   pve-common/trunk/RPCEnvironment.pm
Log:
cleanups


Modified: pve-common/trunk/RPCEnvironment.pm
===================================================================
--- pve-common/trunk/RPCEnvironment.pm	2010-09-15 07:24:56 UTC (rev 5152)
+++ pve-common/trunk/RPCEnvironment.pm	2010-09-15 07:40:45 UTC (rev 5153)
@@ -12,6 +12,41 @@
 
 my $pve_env;
 
+# save $SIG{CHLD} handler implementation.
+# simply set $SIG{CHLD} = $worker_reaper;
+# and register forked processes with &$register_worker(pid)
+# Note: using $SIG{CHLD} = 'IGNORE' or $SIG{CHLD} = sub { wait (); } or ...
+# has serious side effects, because perls built in system() and open()
+# functions can't get the correct exit status of a child. So we cant use 
+# that (also see perlipc)
+
+my $WORKER_PIDS;
+
+my $worker_reaper = sub {
+    local $!; local $?;    
+    foreach my $pid (keys %$WORKER_PIDS) {
+        my $waitpid = waitpid ($pid, WNOHANG);
+        if (defined($waitpid) && ($waitpid == $pid)) {
+            delete ($WORKER_PIDS->{$pid});
+	}
+    }
+};
+
+my $register_worker = sub {
+    my $pid = shift;
+
+    return if !$pid;
+
+    # do not register if already finished
+    my $waitpid = waitpid ($pid, WNOHANG);
+    if (defined($waitpid) && ($waitpid == $pid)) {
+	delete ($WORKER_PIDS->{$pid});
+	return;
+    }
+
+    $WORKER_PIDS->{$pid} = 1;
+};
+
 sub get {
 
     die "not initialized" if !$pve_env;
@@ -28,7 +63,7 @@
 
     die "unknown environment type" if !$type || $type !~ m/^(cli|pub|priv)$/;
 
-    $SIG{CHLD} = &worker_reaper;
+    $SIG{CHLD} = $worker_reaper;
 
     # environment types
     # cli  ... command started fron command line
@@ -134,41 +169,6 @@
     return "UPID:$d->{pid}-$d->{pstart}:$d->{starttime}:$d->{type}:$d->{data}";
 }
 
-# save $SIG{CHLD} handler implementation.
-# simply set $SIG{CHLD} = &worker_reaper;
-# and register forked processes with register_worker(pid)
-# Note: using $SIG{CHLD} = 'IGNORE' or $SIG{CHLD} = sub { wait (); } or ...
-# has serious side effects, because perls built in system() and open()
-# functions can't get the correct exit status of a child. So we cant use 
-# that (also see perlipc)
-
-my $WORKER_PIDS;
-
-sub worker_reaper {
-    local $!; local $?;    
-    foreach my $pid (keys %$WORKER_PIDS) {
-        my $waitpid = waitpid ($pid, WNOHANG);
-        if (defined($waitpid) && ($waitpid == $pid)) {
-            delete ($WORKER_PIDS->{$pid});
-	}
-    }
-}
-
-sub register_worker {
-    my $pid = shift;
-
-    return if !$pid;
-
-    # do not register if already finished
-    my $waitpid = waitpid ($pid, WNOHANG);
-    if (defined($waitpid) && ($waitpid == $pid)) {
-	delete ($WORKER_PIDS->{$pid});
-	return;
-    }
-
-    $WORKER_PIDS->{$pid} = 1;
-}
-
 # start long running workers
 # $data append to the returned uniquely identifier, which
 # has the following format: "UPID:$pid-$pstart:$startime:$dtype:$data"
@@ -178,7 +178,7 @@
 # is writing it
 
 sub fork_worker {
-    my ($dtype, $data, $function) = @_;
+    my ($self, $dtype, $data, $function) = @_;
 
     my $cpid;
 
@@ -309,7 +309,7 @@
 	syslog ('err', "got strange upid - $upid\n");
     }
 
-    register_worker ($cpid);
+    &$register_worker($cpid);
     
     return $upid;
 }



More information about the pve-devel mailing list