mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 11:13:02 +02:00
logging: Protect ShrinkDebugFile by m_cs
We should not be logging while shrinking the debug file, so make sure that's true by using our mutex.
This commit is contained in:
@@ -514,6 +514,8 @@ void BCLog::Logger::LogPrint_(util::log::Entry entry)
|
|||||||
|
|
||||||
void BCLog::Logger::ShrinkDebugFile()
|
void BCLog::Logger::ShrinkDebugFile()
|
||||||
{
|
{
|
||||||
|
STDLOCK(m_cs);
|
||||||
|
|
||||||
// Amount of debug.log to save at end when shrinking (must fit in memory)
|
// Amount of debug.log to save at end when shrinking (must fit in memory)
|
||||||
constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
|
constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
|
||||||
|
|
||||||
@@ -535,7 +537,14 @@ void BCLog::Logger::ShrinkDebugFile()
|
|||||||
// Restart the file with some of the end
|
// Restart the file with some of the end
|
||||||
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
|
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
|
||||||
if (fseek(file, -((long)vch.size()), SEEK_END)) {
|
if (fseek(file, -((long)vch.size()), SEEK_END)) {
|
||||||
LogWarning("Failed to shrink debug log file: fseek(...) failed");
|
// LogWarning, except with m_cs held
|
||||||
|
LogPrint_({
|
||||||
|
.category = BCLog::ALL,
|
||||||
|
.level = Level::Warning,
|
||||||
|
.should_ratelimit = true,
|
||||||
|
.source_loc = SourceLocation{__func__},
|
||||||
|
.message = "Failed to shrink debug log file: fseek(...) failed",
|
||||||
|
});
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ namespace BCLog {
|
|||||||
*/
|
*/
|
||||||
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
|
void DisableLogging() EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
|
||||||
|
|
||||||
void ShrinkDebugFile();
|
void ShrinkDebugFile() EXCLUSIVE_LOCKS_REQUIRED(!m_cs);
|
||||||
|
|
||||||
std::unordered_map<LogFlags, Level> CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
|
std::unordered_map<LogFlags, Level> CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user