From eff59571bef9a3dae8983cd7e55dbb2d81085852 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 23 Jul 2024 10:29:25 +0200 Subject: [PATCH] sysfstools: file_write: properly catch errors since `print` is doing buffered IO, we don't always get an error there, even if the underlying write does not work. To properly catch that, do an unbuffered `syswrite` which circumvents all buffers and writes directly to the file handle. We aren't actually interested in the specific error here, but only if the write was successful or not. Signed-off-by: Dominik Csapak Tested-by: Christoph Heiss --- src/PVE/SysFSTools.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PVE/SysFSTools.pm b/src/PVE/SysFSTools.pm index 57f0ac8..8eb9f2e 100644 --- a/src/PVE/SysFSTools.pm +++ b/src/PVE/SysFSTools.pm @@ -198,7 +198,7 @@ sub file_write { my $fh = IO::File->new($filename, "w"); return undef if !$fh; - my $res = print $fh $buf; + my $res = defined(syswrite($fh, $buf)) ? 1 : 0; $fh->close();