From 9479d422d4b34e2ffd08017272412ab3bd1ae00e Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 10 Dec 2018 17:14:31 -0500 Subject: SL-10153: Use a degenerate singleton for PRELOG log file. The previous build declared a static std::ofstream; but the code that determines the pathname for the log file is called so early that static objects have not yet been constructed. Declare a pointer instead, and instantiate it on demand. --- indra/llvfs/lldir_win32.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'indra/llvfs') diff --git a/indra/llvfs/lldir_win32.cpp b/indra/llvfs/lldir_win32.cpp index 96bd779b5f..e97424c9a9 100644 --- a/indra/llvfs/lldir_win32.cpp +++ b/indra/llvfs/lldir_win32.cpp @@ -30,7 +30,6 @@ #include "lldir_win32.h" #include "llerror.h" -#include "llrand.h" // for gLindenLabRandomNumber #include "stringize.h" #include "llfile.h" #include @@ -47,8 +46,10 @@ DWORD GetDllVersion(LPCTSTR lpszDllName); namespace { // anonymous - enum class prst { INIT, OPEN, SKIP } state; - llofstream prelogf; + enum class prst { INIT, OPEN, SKIP } state = prst::INIT; + // This is called so early that we can't count on static objects being + // properly constructed yet, so declare a pointer instead of an instance. + std::ofstream* prelogf = nullptr; void prelog(const std::string& message) { @@ -64,18 +65,18 @@ namespace if (! prelog_name) // no PRELOG variable set, carry on return; - prelogf.open(prelog_name, std::ios_base::app); - if (! prelogf.is_open()) + prelogf = new std::ofstream(prelog_name, std::ios_base::app); + if (! (prelogf && prelogf->is_open())) // can't complain to anybody; how? return; // got the log file open, cool! state = prst::OPEN; - prelogf << "========================================================================" - << std::endl; + (*prelogf) << "========================================================================" + << std::endl; // fall through, don't break case prst::OPEN: - prelogf << message << std::endl; + (*prelogf) << message << std::endl; break; case prst::SKIP: -- cgit v1.2.3