Merge #13159: Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP)
75ea00f391
Remove unused fsbridge::freopen (practicalswift)cceedbc4bf
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: https://github.com/bitcoin/bitcoin/pull/13148#issuecomment-386288606 Thanks @ajtowns! Tree-SHA512: c436b4286f00fc428b60269b6d6321f435c72c7ccec3c15b2194aac71196529b30f32c2384b418ffe3ed67ba7ee8ec51f4c9c5748e65945697c0437eafcdacd1
This commit is contained in:
commit
bb0277819a
3 changed files with 5 additions and 11 deletions
|
@ -14,11 +14,6 @@ FILE *fopen(const fs::path& p, const char *mode)
|
||||||
return ::fopen(p.string().c_str(), 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
|
|
||||||
static std::string GetErrorReason() {
|
static std::string GetErrorReason() {
|
||||||
|
|
1
src/fs.h
1
src/fs.h
|
@ -18,7 +18,6 @@ namespace fs = boost::filesystem;
|
||||||
/** Bridge operations to C stdio */
|
/** Bridge operations to C stdio */
|
||||||
namespace fsbridge {
|
namespace fsbridge {
|
||||||
FILE *fopen(const fs::path& p, const char *mode);
|
FILE *fopen(const fs::path& p, const char *mode);
|
||||||
FILE *freopen(const fs::path& p, const char *mode, FILE *stream);
|
|
||||||
|
|
||||||
class FileLock
|
class FileLock
|
||||||
{
|
{
|
||||||
|
|
|
@ -219,13 +219,13 @@ void BCLog::Logger::LogPrintStr(const std::string &str)
|
||||||
// reopen the log file, if requested
|
// reopen the log file, if requested
|
||||||
if (m_reopen_file) {
|
if (m_reopen_file) {
|
||||||
m_reopen_file = false;
|
m_reopen_file = false;
|
||||||
m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout);
|
FILE* new_fileout = fsbridge::fopen(m_file_path, "a");
|
||||||
if (!m_fileout) {
|
if (new_fileout) {
|
||||||
return;
|
setbuf(new_fileout, nullptr); // unbuffered
|
||||||
|
fclose(m_fileout);
|
||||||
|
m_fileout = new_fileout;
|
||||||
}
|
}
|
||||||
setbuf(m_fileout, nullptr); // unbuffered
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileWriteStr(strTimestamped, m_fileout);
|
FileWriteStr(strTimestamped, m_fileout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue