]> git.proxmox.com Git - pve-common.git/commitdiff
add readline_nointr to Tools
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 21 Aug 2018 13:07:24 +0000 (15:07 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 22 Aug 2018 13:32:56 +0000 (15:32 +0200)
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@proxmox.com>
src/PVE/Tools.pm

index 0a7efeb8dce920d1904d651b66d1b20234ff1e46..4a8b5d9b530521af9c6a033da6ad2a4952e5bc07 100644 (file)
@@ -1596,4 +1596,16 @@ sub convert_size {
     return int($value);
 }
 
     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;
 1;