[pve-devel] [PATCH common 1/2] add readline_nointr to Tools

Dominik Csapak d.csapak at proxmox.com
Tue Aug 21 15:07:24 CEST 2018


this is a wrapper to have an uninterruptible readline
so that we can read e.g. from a pipe even if interrupted by
a signal

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/Tools.pm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 0a7efeb..4a8b5d9 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -1596,4 +1596,16 @@ sub convert_size {
     return int($value);
 }
 
+# uninterruptible readline
+# retries on EINTR
+sub readline_nointr {
+    my ($fh) = @_;
+    my $line;
+    while (1) {
+	$line = <$fh>;
+	last if defined($line) || ($! != EINTR);
+    }
+    return $line;
+}
+
 1;
-- 
2.11.0





More information about the pve-devel mailing list