diff options
Diffstat (limited to 'indra/llcrashlogger/llcrashlogger.cpp')
-rw-r--r-- | indra/llcrashlogger/llcrashlogger.cpp | 104 |
1 files changed, 68 insertions, 36 deletions
diff --git a/indra/llcrashlogger/llcrashlogger.cpp b/indra/llcrashlogger/llcrashlogger.cpp index 68e45f36e4..3461aa3e6c 100644 --- a/indra/llcrashlogger/llcrashlogger.cpp +++ b/indra/llcrashlogger/llcrashlogger.cpp @@ -31,15 +31,18 @@ #include "llcrashlogger.h" #include "linden_common.h" #include "llstring.h" -#include "indra_constants.h" // CRASH_BEHAVIOR_ASK, CRASH_SETTING_NAME +#include "indra_constants.h" // CRASH_BEHAVIOR_... #include "llerror.h" +#include "llerrorcontrol.h" #include "lltimer.h" #include "lldir.h" +#include "llfile.h" #include "llsdserialize.h" #include "lliopipe.h" #include "llpumpio.h" #include "llhttpclient.h" #include "llsdserialize.h" +#include "llproxy.h" LLPumpIO* gServicePump; BOOL gBreak = false; @@ -54,7 +57,7 @@ public: virtual void error(U32 status, const std::string& reason) { - gBreak = true; + gBreak = true; } virtual void result(const LLSD& content) @@ -64,21 +67,8 @@ public: } }; -bool LLCrashLoggerText::mainLoop() -{ - std::cout << "Entering main loop" << std::endl; - sendCrashLogs(); - return true; -} - -void LLCrashLoggerText::updateApplication(const std::string& message) -{ - LLCrashLogger::updateApplication(message); - std::cout << message << std::endl; -} - LLCrashLogger::LLCrashLogger() : - mCrashBehavior(CRASH_BEHAVIOR_ASK), + mCrashBehavior(CRASH_BEHAVIOR_ALWAYS_SEND), mCrashInPreviousExec(false), mCrashSettings("CrashSettings"), mSentCrashLogs(false), @@ -281,26 +271,48 @@ LLSD LLCrashLogger::constructPostData() return mCrashInfo; } +const char* const CRASH_SETTINGS_FILE = "settings_crash_behavior.xml"; + S32 LLCrashLogger::loadCrashBehaviorSetting() { + // First check user_settings (in the user's home dir) std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE); + if (! mCrashSettings.loadFromFile(filename)) + { + // Next check app_settings (in the SL program dir) + std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, CRASH_SETTINGS_FILE); + mCrashSettings.loadFromFile(filename); + } - mCrashSettings.loadFromFile(filename); - - S32 value = mCrashSettings.getS32(CRASH_BEHAVIOR_SETTING); - - if (value < CRASH_BEHAVIOR_ASK || CRASH_BEHAVIOR_NEVER_SEND < value) return CRASH_BEHAVIOR_ASK; + // If we didn't load any files above, this will return the default + S32 value = mCrashSettings.getS32("CrashSubmitBehavior"); + + // Whatever value we got, make sure it's valid + switch (value) + { + case CRASH_BEHAVIOR_NEVER_SEND: + return CRASH_BEHAVIOR_NEVER_SEND; + case CRASH_BEHAVIOR_ALWAYS_SEND: + return CRASH_BEHAVIOR_ALWAYS_SEND; + } - return value; + return CRASH_BEHAVIOR_ASK; } bool LLCrashLogger::saveCrashBehaviorSetting(S32 crash_behavior) { - if (crash_behavior != CRASH_BEHAVIOR_ASK && crash_behavior != CRASH_BEHAVIOR_ALWAYS_SEND) return false; + switch (crash_behavior) + { + case CRASH_BEHAVIOR_ASK: + case CRASH_BEHAVIOR_NEVER_SEND: + case CRASH_BEHAVIOR_ALWAYS_SEND: + break; + default: + return false; + } - mCrashSettings.setS32(CRASH_BEHAVIOR_SETTING, crash_behavior); + mCrashSettings.setS32("CrashSubmitBehavior", crash_behavior); std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE); - mCrashSettings.saveToFile(filename, FALSE); return true; @@ -309,14 +321,13 @@ bool LLCrashLogger::saveCrashBehaviorSetting(S32 crash_behavior) bool LLCrashLogger::runCrashLogPost(std::string host, LLSD data, std::string msg, int retries, int timeout) { gBreak = false; - std::string status_message; for(int i = 0; i < retries; ++i) { - status_message = llformat("%s, try %d...", msg.c_str(), i+1); + updateApplication(llformat("%s, try %d...", msg.c_str(), i+1)); LLHTTPClient::post(host, data, new LLCrashLoggerResponder(), timeout); while(!gBreak) { - updateApplication(status_message); + updateApplication(); // No new message, just pump the IO } if(gSent) { @@ -336,7 +347,7 @@ bool LLCrashLogger::sendCrashLogs() updateApplication("Sending reports..."); std::string dump_path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, - "SecondLifeCrashReport"); + "SecondLifeCrashReport"); std::string report_file = dump_path + ".log"; std::ofstream out_file(report_file.c_str()); @@ -365,23 +376,37 @@ void LLCrashLogger::updateApplication(const std::string& message) { gServicePump->pump(); gServicePump->callback(); + if (!message.empty()) llinfos << message << llendl; } bool LLCrashLogger::init() { - LLCurl::initClass(); + LLCurl::initClass(false); // We assume that all the logs we're looking for reside on the current drive gDirUtilp->initAppDirs("SecondLife"); + LLError::initForApplication(gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "")); + // Default to the product name "Second Life" (this is overridden by the -name argument) mProductName = "Second Life"; + + // Rename current log file to ".old" + std::string old_log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "crashreport.log.old"); + std::string log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "crashreport.log"); + LLFile::rename(log_file.c_str(), old_log_file.c_str()); + + // Set the log file to crashreport.log + LLError::logToFile(log_file); - mCrashSettings.declareS32(CRASH_BEHAVIOR_SETTING, CRASH_BEHAVIOR_ASK, "Controls behavior when viewer crashes " - "(0 = ask before sending crash report, 1 = always send crash report, 2 = never send crash report)"); + mCrashSettings.declareS32("CrashSubmitBehavior", CRASH_BEHAVIOR_ALWAYS_SEND, + "Controls behavior when viewer crashes " + "(0 = ask before sending crash report, " + "1 = always send crash report, " + "2 = never send crash report)"); - llinfos << "Loading crash behavior setting" << llendl; - mCrashBehavior = loadCrashBehaviorSetting(); + // llinfos << "Loading crash behavior setting" << llendl; + // mCrashBehavior = loadCrashBehaviorSetting(); // If user doesn't want to send, bail out if (mCrashBehavior == CRASH_BEHAVIOR_NEVER_SEND) @@ -394,12 +419,19 @@ bool LLCrashLogger::init() gServicePump->prime(gAPRPoolp); LLHTTPClient::setPump(*gServicePump); - //If we've opened the crash logger, assume we can delete the marker file if it exists + //If we've opened the crash logger, assume we can delete the marker file if it exists if( gDirUtilp ) { - std::string marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,"SecondLife.exec_marker"); + std::string marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, + "SecondLife.exec_marker"); LLAPRFile::remove( marker_file ); } return true; } + +// For cleanup code common to all platforms. +void LLCrashLogger::commonCleanup() +{ + LLProxy::cleanupClass(); +} |