]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/ProcFSTools.pm
add upid_wait method
[pve-common.git] / src / PVE / ProcFSTools.pm
index 99f767a172b7e1f0bc687d44c043a8123fd0d347..516c0e8b939791a64771df41c36df362e65c7423 100644 (file)
@@ -352,4 +352,24 @@ sub read_proc_net_ipv6_route {
     return $res;
 }
 
+sub upid_wait {
+    my ($upid, $waitfunc, $sleep_intervall) = @_;
+
+    my $task = PVE::Tools::upid_decode($upid);
+
+    $sleep_intervall = $sleep_intervall ? $sleep_intervall : 1;
+
+    my $next_time = time + $sleep_intervall;
+
+    while (check_process_running($task->{pid}, $task->{pstart})) {
+
+       if (time >= $next_time && $waitfunc && ref($waitfunc) eq 'CODE'){
+           &$waitfunc($task);
+           $next_time = time + $sleep_intervall;
+       }
+
+       CORE::sleep(1);
+    }
+}
+
 1;