DRTVWR-476: Partially revert 978e09882565: undo using LLTempRedirect.

But leave LLTempRedirect available in the code base.
meow-7.2.2
Nat Goodspeed 2019-11-12 16:54:56 -05:00
parent 7ef10fe11c
commit 950204a5d7
1 changed files with 38 additions and 10 deletions

View File

@ -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,10 +572,18 @@ 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()
{
return mSettingsConfig;
@ -583,7 +611,7 @@ namespace LLError
int Settings::getDupStderr() const
{
return mRedirect.getOriginalTarget();
return mDupStderr;
}
bool is_available()