[pve-devel] [PATCH common 1/1] sysfstools: file_write: log the actual error if there was one

Dominik Csapak d.csapak at proxmox.com
Tue Nov 5 10:24:20 CET 2024


the actual error and path is useful to know when tryin to debug or
figure out what did not work, so warn here if there was an error.

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

diff --git a/src/PVE/SysFSTools.pm b/src/PVE/SysFSTools.pm
index 0bde6d7..d0d1bb9 100644
--- a/src/PVE/SysFSTools.pm
+++ b/src/PVE/SysFSTools.pm
@@ -217,7 +217,12 @@ sub file_write {
     my $fh = IO::File->new($filename, "w");
     return undef if !$fh;
 
-    my $res = defined(syswrite($fh, $buf)) ? 1 : 0;
+    my $res = 0;
+    if (defined(syswrite($fh, $buf))) {
+	$res = 1;
+    } elsif (my $err = $!) {
+	warn "error writing '$buf' to '$filename': $err\n";
+    }
 
     $fh->close();
 
-- 
2.39.5





More information about the pve-devel mailing list