From c93face831a99c60f6ad1fdcd0df8b254b409d37 Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 5 Oct 2018 10:17:31 +0200 Subject: [PATCH] clusterd: Add checks for write errors Currently we may move received files in place, even whe the write or close were unsuccessfull (eg. disk full). This is a serious bug and we may end up with an empty passwd. Add checks for all write() and close() calls. Also log rename errors. --- clusterd/clusterd | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/clusterd/clusterd b/clusterd/clusterd index 769e374..6473661 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -895,12 +895,12 @@ sub udp_rx_filedata { # complete file in one broadcast my $fh=IO::File->new($tmp_filename,O_WRONLY|O_CREAT,0); defined $fh or return warn "$tmp_filename: $!\n"; - $fh->syswrite($data); - $fh->close; + $fh->syswrite($data) or return warn "$tmp_filename: $!\n"; + $fh->close or return warn "$tmp_filename: $!\n"; chown $st_want->uid,$st_want->gid,$tmp_filename or return warn "$tmp_filename: $!\n"; chmod $st_want->perm,$tmp_filename or return warn "$tmp_filename: $!\n"; $st_is and unlink($filename); - rename($tmp_filename,$filename); + rename($tmp_filename,$filename) or return warn "rename $tmp_filename $filename: $!\n"; utime($st_want->mtime,$st_want->mtime,$filename); warn "installed $filename\n"; $rx_filedata_done=1; @@ -945,7 +945,7 @@ sub udp_rx_filedata { chown $st_want->uid,$st_want->gid,$tmp_filename or return warn "$tmp_filename: $!\n"; chmod $st_want->perm,$tmp_filename or return warn "$tmp_filename: $!\n"; $st_is and unlink($filename); - rename($tmp_filename,$filename); + rename($tmp_filename,$filename) or return warn "rename $tmp_filename $filename: $!\n"; utime($st_want->mtime,$st_want->mtime,$filename); warn "installed $filename\n"; delete $RECEIVER{$filename}; @@ -1753,10 +1753,10 @@ sub udp_rx_push { if ($st_want->size==0) { my $fh=IO::File->new($tmp_filename,O_WRONLY|O_CREAT,0); defined $fh or return warn "$tmp_filename: $!\n"; - $fh->close; + $fh->close or return warn "$tmp_filename: $!\n"; chown $st_want->uid,$st_want->gid,$tmp_filename or return warn "$tmp_filename: $!\n"; chmod $st_want->perm,$tmp_filename or return warn "$tmp_filename: $!\n"; - rename($tmp_filename,$filename); + rename($tmp_filename,$filename) or return warn "rename $tmp_filename $filename: $!\n";; utime($st_want->mtime,$st_want->mtime,$filename); warn "installed (empty) $filename\n"; return; @@ -1777,17 +1777,17 @@ sub udp_rx_push { my ($buf)=@_; if ($!) { warn "$ip: $!\n";$cb=undef;return; } if (length($buf)==0) { warn "$ip: EOF\n";$cb=undef;return;} - print $fh $buf; + print $fh $buf or return warn "$tmp_filename: $!\n"; $bytes-=length($buf); if ($bytes>0) { My::Select::INET::read_with_timeout($s,$cb,$TCP_TIMEOUT); return; } $cb=undef; - close $fh; + close $fh or return warn "$tmp_filename: $!\n"; chown $st_want->uid,$st_want->gid,$tmp_filename or return warn "$tmp_filename: $!\n"; chmod $st_want->perm,$tmp_filename or return warn "$tmp_filename: $!\n"; - rename($tmp_filename,$filename) or return warn "$filename: $!\n"; + rename($tmp_filename,$filename) or return warn "rename $tmp_filename $filename: $!\n"; utime($st_want->mtime,$st_want->mtime,$filename); warn "installed $filename\n"; };