From e03a836591446125527230ed150669943307832b Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 21 Aug 2018 15:07:24 +0200 Subject: [PATCH] add readline_nointr to Tools 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 --- 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.39.2