aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sadie Powell2021-02-01 18:10:53 +0000
committerGravatar Sadie Powell2021-02-01 18:10:53 +0000
commitaa4c7489b708eb54856871ecdf2bbde99fde92bc (patch)
tree21558052ff2f8c6062707920455ea425974379c7
parentFix using the TR1 headers on compilers that support C++17. (diff)
downloadinspircd++-aa4c7489b708eb54856871ecdf2bbde99fde92bc.tar.gz
inspircd++-aa4c7489b708eb54856871ecdf2bbde99fde92bc.tar.bz2
inspircd++-aa4c7489b708eb54856871ecdf2bbde99fde92bc.zip
Duplicate the stdout file handle when used for logging.
Failure to do this may result in a crash on shutdown when started in debug mode.
-rw-r--r--src/inspircd.cpp3
-rw-r--r--win/inspircd_win32wrapper.h2
2 files changed, 4 insertions, 1 deletions
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index ba7e08eff..8cbb83d6f 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -524,7 +524,8 @@ InspIRCd::InspIRCd(int argc, char** argv)
if (Config->cmdline.forcedebug)
{
- FileWriter* fw = new FileWriter(stdout, 1);
+ FILE* newstdout = fdopen(dup(STDOUT_FILENO), "w");
+ FileWriter* fw = new FileWriter(newstdout, 1);
FileLogStream* fls = new FileLogStream(LOG_RAWIO, fw);
Logs->AddLogTypes("*", fls, true);
}
diff --git a/win/inspircd_win32wrapper.h b/win/inspircd_win32wrapper.h
index 7366fc336..368504d61 100644
--- a/win/inspircd_win32wrapper.h
+++ b/win/inspircd_win32wrapper.h
@@ -102,6 +102,8 @@ typedef SSIZE_T ssize_t;
#define popen _popen
#define pclose _pclose
#define getpid _getpid
+#define dup _dup
+#define fdopen _fdopen
// warning: 'identifier' : class 'type' needs to have dll-interface to be used by clients of class 'type2'
// Normally, this is a huge problem, but due to our new/delete remap, we can ignore it.