Skip to content

Commit 3ab5087

Browse files
authored
[7.8][ML] Only log failure to ignore SIGPIPE once (#1233)
The warning if something stops SIGPIPE being ignored has always been deferred as the signal calls are made before main() has run. However, the place the warning was deferred to could result in it being logged many times because the deferred logging was in a method that could be called many times. This change moves that deferred logging to a dedicated method that can just be called once. Backport of #1221
1 parent cb208bd commit 3ab5087

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

include/core/CNamedPipeFactory.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ class CORE_EXPORT CNamedPipeFactory : private CNonInstantiatable {
9090
//! Default path for named pipes.
9191
static std::string defaultPath();
9292

93+
//! Log warnings that have been stored because they were detected very
94+
//! early in the program lifecycle. Programs using named pipes should
95+
//! call this method once, after setting up logging.
96+
static void logDeferredWarnings();
97+
9398
private:
9499
#ifdef Windows
95100
using TPipeHandle = HANDLE;

lib/core/CLogger.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ bool CLogger::reconfigureLogToNamedPipe(const std::string& pipeName) {
314314

315315
LOG_DEBUG(<< "Logger is logging to named pipe " << pipeName);
316316

317+
CNamedPipeFactory::logDeferredWarnings();
318+
317319
return true;
318320
}
319321

lib/core/CNamedPipeFactory.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,15 @@ std::string CNamedPipeFactory::defaultPath() {
173173
return path;
174174
}
175175

176-
CNamedPipeFactory::TPipeHandle
177-
CNamedPipeFactory::initPipeHandle(const std::string& fileName, bool forWrite) {
178-
if (!SIGPIPE_IGNORED) {
176+
void CNamedPipeFactory::logDeferredWarnings() {
177+
if (SIGPIPE_IGNORED == false) {
179178
LOG_WARN(<< "Failed to ignore SIGPIPE - this process will not terminate "
180179
"gracefully if a process it is writing to via a named pipe dies");
181180
}
181+
}
182182

183+
CNamedPipeFactory::TPipeHandle
184+
CNamedPipeFactory::initPipeHandle(const std::string& fileName, bool forWrite) {
183185
bool madeFifo(false);
184186

185187
// If the name already exists, ensure it refers directly (i.e. not via a

lib/core/CNamedPipeFactory_Windows.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ std::string CNamedPipeFactory::defaultPath() {
8383
return PIPE_PREFIX;
8484
}
8585

86+
void CNamedPipeFactory::logDeferredWarnings() {
87+
// No-op
88+
}
89+
8690
CNamedPipeFactory::TPipeHandle
8791
CNamedPipeFactory::initPipeHandle(const std::string& fileName, bool forWrite) {
8892
// Size of named pipe buffer

0 commit comments

Comments
 (0)