5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-01-09 05:17:35 +03:00

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 <d.csapak@proxmox.com>
Tested-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
Dominik Csapak 2024-07-23 10:29:25 +02:00 committed by Thomas Lamprecht
parent 5b0106ebee
commit eff59571be

View File

@ -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();