Handle unsuccessful fseek(...):s.
Note to reviewers: What is the most appropriate course of actions for each of these unsuccessful fseek(...):s?
Handle unsuccessful fseek(...):s.
Note to reviewers: What is the most appropriate course of actions for each of these unsuccessful fseek(...):s?
886 | @@ -887,7 +887,9 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) { 887 | // Fallback version 888 | // TODO: just write one byte per block 889 | static const char buf[65536] = {}; 890 | - fseek(file, offset, SEEK_SET); 891 | + if (fseek(file, offset, SEEK_SET)) { 892 | + return;
Just returning here is fine - this call is only advisory.
253 | @@ -254,7 +254,10 @@ void BCLog::Logger::ShrinkDebugFile() 254 | { 255 | // Restart the file with some of the end 256 | std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0); 257 | - fseek(file, -((long)vch.size()), SEEK_END); 258 | + if (fseek(file, -((long)vch.size()), SEEK_END)) {
Not sure what should be done here. As-is it will silently fail to shrink the log file but should continue logging otherwise? Maybe log an error message?
Agree with @laanwj: an additional error message would make sense.
267 | @@ -268,7 +268,9 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe 268 | CBlockHeader header; 269 | try { 270 | file >> header; 271 | - fseek(file.Get(), postx.nTxOffset, SEEK_CUR); 272 | + if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) { 273 | + return error("%s: fseek(...) failed", __func__);
LGTM
utACK 29c9bdcc141afb14fc9e1213f49de4fcded6ce0c (though a LogPrint in ShrinkDebugFile() would be even better).
@laanwj @jonasschnelli Regarding logging in ShrinkDebugFile(…) – what about the following:
diff --git a/src/logging.cpp b/src/logging.cpp
index 2a55d36..b57b17e 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -255,6 +255,7 @@ void BCLog::Logger::ShrinkDebugFile()
// Restart the file with some of the end
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
if (fseek(file, -((long)vch.size()), SEEK_END)) {
+ LogPrintf("Failed to shrink debug file: fseek(...) failed\n");
fclose(file);
return;
}
Looks good?
@practicalswift maybe "debug log file" instead of "debug file"?
@laanwj @jonasschnelli Added a commit for the logging. Please re-review :-)
utACK 20ce5af4c647d9ebd97b40683bd0747383c9dc20
utACK 20ce5af