[pve-devel] [PATCH common] tools: more general run_fork_with_timeout + run_fork
Wolfgang Bumiller
w.bumiller at proxmox.com
Tue Oct 10 10:08:12 CEST 2017
---
We have run_fork_with_timeout in order to run a piece of code
in a fork while being able to return values from it and pass
along exceptions, but we still had no way of doing this without
a timeout...
src/PVE/Tools.pm | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index bd99914..2525e55 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -945,7 +945,11 @@ sub run_fork_with_timeout {
$error = $child_res->{error};
};
eval {
- run_with_timeout($timeout, $readvalues);
+ if (defined($timeout)) {
+ run_with_timeout($timeout, $readvalues);
+ } else {
+ $readvalues->();
+ }
};
warn $@ if $@;
$pipe_out->close();
@@ -959,6 +963,11 @@ sub run_fork_with_timeout {
return $res;
}
+sub run_fork {
+ my ($code) = @_;
+ return run_fork_with_timeout(undef, $code);
+}
+
# NOTE: NFS syscall can't be interrupted, so alarm does
# not work to provide timeouts.
# from 'man nfs': "Only SIGKILL can interrupt a pending NFS operation"
--
2.11.0
More information about the pve-devel
mailing list