diff options
| author | Nat Goodspeed <nat@lindenlab.com> | 2019-11-12 16:54:56 -0500 | 
|---|---|---|
| committer | Nat Goodspeed <nat@lindenlab.com> | 2020-03-25 19:06:13 -0400 | 
| commit | 950204a5d77c2681e369efdc45a7dc7b8348ee75 (patch) | |
| tree | 32d1703eaa05fd015364dfa6e4b813045408cb0e | |
| parent | 7ef10fe11c0221ae4ac1a46eae378aafc178296d (diff) | |
DRTVWR-476: Partially revert 978e09882565: undo using LLTempRedirect.
But leave LLTempRedirect available in the code base.
| -rw-r--r-- | indra/llcommon/llerror.cpp | 48 | 
1 files changed, 38 insertions, 10 deletions
| diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index 9a475464f4..d9f299b2d9 100644 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -39,6 +39,8 @@  #if !LL_WINDOWS  # include <syslog.h>  # include <unistd.h> +#else +# include <io.h>  #endif // !LL_WINDOWS  #include <vector>  #include "string.h" @@ -52,7 +54,20 @@  #include "llsingleton.h"  #include "llstl.h"  #include "lltimer.h" -#include "lltempredirect.h" + +#if LL_WINDOWS +#define fhclose  _close +#define fhdup    _dup +#define fhdup2   _dup2 +#define fhfdopen _fdopen +#define fhfileno _fileno +#else +#define fhclose  ::close +#define fhdup    ::dup +#define fhdup2   ::dup2 +#define fhfdopen ::fdopen +#define fhfileno ::fileno +#endif  namespace LLError  { @@ -65,6 +80,7 @@ namespace LLError  		LLSINGLETON(Settings);  	public:  		SettingsConfigPtr getSettingsConfig(); +		~Settings();  		void reset();  		SettingsStoragePtr saveAndReset(); @@ -74,7 +90,7 @@ namespace LLError  	private:  		SettingsConfigPtr mSettingsConfig; -		LLTempRedirect mRedirect; +		int mDupStderr;  	};  } // namespace LLError @@ -146,7 +162,8 @@ namespace {  	public:  		RecordToFile(const std::string& filename):  			mName(filename), -			mFile(LLFile::fopen(filename, "a")) +			mFile(LLFile::fopen(filename, "a")), +			mSavedStderr(LLError::Settings::instance().getDupStderr())  		{  			if (!mFile)  			{ @@ -157,13 +174,16 @@ namespace {  				// We use a number of classic-C libraries, some of which write  				// log output to stderr. The trouble with that is that unless  				// you launch the viewer from a console, stderr output is -				// lost. Redirect stderr to write into this log file. -				mRedirect = LLTempRedirect(mFile, stderr); +				// lost. Redirect STDERR_FILENO to write into this log file. +				fhdup2(fhfileno(mFile), fhfileno(stderr));  			}  		}  		~RecordToFile()  		{ +			// restore stderr to its original fileno so any subsequent output +			// to stderr goes to original stream +			fhdup2(mSavedStderr, fhfileno(stderr));  			mFile.close();  		} @@ -194,7 +214,7 @@ namespace {  	private:  		const std::string mName;  		LLUniqueFile mFile; -		LLTempRedirect mRedirect; +		int mSavedStderr;  	}; @@ -205,7 +225,7 @@ namespace {  			mUseANSI(checkANSI()),  			// use duplicate stderr file handle so THIS output isn't affected  			// by our internal redirection of all (other) stderr output -			mStderr(llfd::open(LLError::Settings::instance().getDupStderr(), "a")) +			mStderr(fhfdopen(LLError::Settings::instance().getDupStderr(), "a"))  		{  			this->showMultiline(true);  		} @@ -256,7 +276,7 @@ namespace {  			// Check whether it's okay to use ANSI; if stderr is  			// a tty then we assume yes.  Can be turned off with  			// the LL_NO_ANSI_COLOR env var. -			return (0 != isatty(fileno(stderr))) && +			return (0 != isatty(fhfileno(stderr))) &&  				(NULL == getenv("LL_NO_ANSI_COLOR"));  #endif // LL_LINUX  			return false; @@ -552,8 +572,16 @@ namespace LLError  	Settings::Settings():  		mSettingsConfig(new SettingsConfig()),  		// duplicate stderr file handle right away -		mRedirect(NULL, stderr) +		mDupStderr(fhdup(fhfileno(stderr))) +	{ +	} + +	Settings::~Settings()  	{ +		// restore original stderr +		fhdup2(mDupStderr, fhfileno(stderr)); +		// and close the duplicate +		fhclose(mDupStderr);  	}  	SettingsConfigPtr Settings::getSettingsConfig() @@ -583,7 +611,7 @@ namespace LLError  	int Settings::getDupStderr() const  	{ -		return mRedirect.getOriginalTarget(); +		return mDupStderr;  	}  	bool is_available() | 
