Skip to content

Commit

Permalink
Merge #13159: Don't close old debug log file handle prematurely when …
Browse files Browse the repository at this point in the history
…trying to re-open (on SIGHUP)

Summary:
75ea00f391b742e435c650aae3e827aad913d552 Remove unused fsbridge::freopen (practicalswift)
cceedbc4bf1056db17e0adf76d0db45b94777671 Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP) (practicalswift)

Pull request description:

  Don't close old debug log file handle prematurely when trying to re-open (on `SIGHUP`).

  Context: bitcoin/bitcoin#13148 (comment)

  Thanks @ajtowns!

Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1

Backport of Core PR13159
bitcoin/bitcoin#13159

Depends on D3976

Test Plan:
  make check
  ./bitcoind -regtest -daemon
  cd <path>/.bitcoin/regtest
  mv debug.log{,.old}
  touch debug.log; chmod 400 debug.log
  killall -HUP bitcoind
  <patch>/bitcoin-abc/build/src/bitcoin-cli -regtest savemempool
Verify that the new debug.log file is empty and debug.log.old continued to be written to

Reviewers: deadalnix, Fabien, jasonbcox, O1 Bitcoin ABC, #bitcoin_abc

Reviewed By: Fabien, O1 Bitcoin ABC, #bitcoin_abc

Differential Revision: https://reviews.bitcoinabc.org/D3979
  • Loading branch information
laanwj authored and proteanx committed Dec 23, 2019
1 parent 268df15 commit 9108266
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
3 changes: 0 additions & 3 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@ FILE *fopen(const fs::path &p, const char *mode) {
return ::fopen(p.string().c_str(), mode);
}

FILE *freopen(const fs::path &p, const char *mode, FILE *stream) {
return ::freopen(p.string().c_str(), mode, stream);
}

} // fsbridge
3 changes: 1 addition & 2 deletions src/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace fs = boost::filesystem;
/** Bridge operations to C stdio */
namespace fsbridge {
FILE *fopen(const fs::path &p, const char *mode);
FILE *freopen(const fs::path &p, const char *mode, FILE *stream);
};
}; // namespace fsbridge

// clang-format on
12 changes: 6 additions & 6 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ void BCLog::Logger::LogPrintStr(const std::string &str) {
if (m_reopen_file) {
m_reopen_file = false;
fs::path pathDebug = GetDebugLogPath();
m_fileout = fsbridge::freopen(pathDebug, "a", m_fileout);
if (!m_fileout) {
return;
FILE *new_fileout = fsbridge::fopen(pathDebug, "a");
if (new_fileout) {
// unbuffered.
setbuf(m_fileout, nullptr);
fclose(m_fileout);
m_fileout = new_fileout;
}
// unbuffered.
setbuf(m_fileout, nullptr);
}

FileWriteStr(strTimestamped, m_fileout);
}
}
Expand Down

0 comments on commit 9108266

Please sign in to comment.