Skip to content

Commit bb02778

Browse files
committed
Merge #13159: Don't close old debug log file handle prematurely when trying to re-open (on SIGHUP)
75ea00f Remove unused fsbridge::freopen (practicalswift) cceedbc 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
2 parents 104aad1 + 75ea00f commit bb02778

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

src/fs.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ FILE *fopen(const fs::path& p, const char *mode)
1414
return ::fopen(p.string().c_str(), mode);
1515
}
1616

17-
FILE *freopen(const fs::path& p, const char *mode, FILE *stream)
18-
{
19-
return ::freopen(p.string().c_str(), mode, stream);
20-
}
21-
2217
#ifndef WIN32
2318

2419
static std::string GetErrorReason() {

src/fs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace fs = boost::filesystem;
1818
/** Bridge operations to C stdio */
1919
namespace fsbridge {
2020
FILE *fopen(const fs::path& p, const char *mode);
21-
FILE *freopen(const fs::path& p, const char *mode, FILE *stream);
2221

2322
class FileLock
2423
{

src/logging.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,13 @@ void BCLog::Logger::LogPrintStr(const std::string &str)
219219
// reopen the log file, if requested
220220
if (m_reopen_file) {
221221
m_reopen_file = false;
222-
m_fileout = fsbridge::freopen(m_file_path, "a", m_fileout);
223-
if (!m_fileout) {
224-
return;
222+
FILE* new_fileout = fsbridge::fopen(m_file_path, "a");
223+
if (new_fileout) {
224+
setbuf(new_fileout, nullptr); // unbuffered
225+
fclose(m_fileout);
226+
m_fileout = new_fileout;
225227
}
226-
setbuf(m_fileout, nullptr); // unbuffered
227228
}
228-
229229
FileWriteStr(strTimestamped, m_fileout);
230230
}
231231
}

0 commit comments

Comments
 (0)