From 42daa3497b6626cbb5f32ba54162558cd025069b Mon Sep 17 00:00:00 2001
From: Aaron Stone <stone@lindenlab.com>
Date: Tue, 12 Jul 2011 15:48:02 -0700
Subject: STORM-1482 The Viewer shouldn't overwrite the crash behavior
 settings, some cleanups to the crash reporters, and the ability to use --set
 GroupName.SettingName to set parameters outside of the (default) Global
 settings group.

---
 indra/llcrashlogger/llcrashlogger.cpp | 80 +++++++++++++++++++++--------------
 indra/llcrashlogger/llcrashlogger.h   | 11 -----
 2 files changed, 49 insertions(+), 42 deletions(-)

(limited to 'indra/llcrashlogger')

diff --git a/indra/llcrashlogger/llcrashlogger.cpp b/indra/llcrashlogger/llcrashlogger.cpp
index 68e45f36e4..3fbaf61991 100644
--- a/indra/llcrashlogger/llcrashlogger.cpp
+++ b/indra/llcrashlogger/llcrashlogger.cpp
@@ -31,10 +31,12 @@
 #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"
@@ -54,7 +56,7 @@ public:
 
 	virtual void error(U32 status, const std::string& reason)
 	{
-		gBreak = true;		
+		gBreak = true;
 	}
 
 	virtual void result(const LLSD& content)
@@ -64,19 +66,6 @@ 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),
 	mCrashInPreviousExec(false),
@@ -281,26 +270,41 @@ LLSD LLCrashLogger::constructPostData()
 	return mCrashInfo;
 }
 
+const char* const CRASH_SETTINGS_FILE = "settings_crash_behavior.xml";
+
 S32 LLCrashLogger::loadCrashBehaviorSetting()
 {
 	std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE);
 
 	mCrashSettings.loadFromFile(filename);
-		
-	S32 value = mCrashSettings.getS32(CRASH_BEHAVIOR_SETTING);
-	
-	if (value < CRASH_BEHAVIOR_ASK || CRASH_BEHAVIOR_NEVER_SEND < value) return CRASH_BEHAVIOR_ASK;
 
-	return value;
+	S32 value = mCrashSettings.getS32("CrashSubmitBehavior");
+
+	switch (value)
+	{
+	case CRASH_BEHAVIOR_NEVER_SEND:
+		return CRASH_BEHAVIOR_NEVER_SEND;
+	case CRASH_BEHAVIOR_ALWAYS_SEND:
+		return CRASH_BEHAVIOR_ALWAYS_SEND;
+	}
+
+	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 +313,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 +339,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,6 +368,7 @@ void LLCrashLogger::updateApplication(const std::string& message)
 {
 	gServicePump->pump();
     gServicePump->callback();
+	if (!message.empty()) llinfos << message << llendl;
 }
 
 bool LLCrashLogger::init()
@@ -374,11 +378,24 @@ bool LLCrashLogger::init()
 	// 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_ASK,
+							  "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();
@@ -394,10 +411,11 @@ 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 );
 	}
 	
diff --git a/indra/llcrashlogger/llcrashlogger.h b/indra/llcrashlogger/llcrashlogger.h
index a5daa74247..5d0cb5931c 100644
--- a/indra/llcrashlogger/llcrashlogger.h
+++ b/indra/llcrashlogger/llcrashlogger.h
@@ -66,15 +66,4 @@ protected:
 	bool mSentCrashLogs;
 };
 
-class LLCrashLoggerText : public LLCrashLogger
-{
-public:
-	LLCrashLoggerText(void) {}
-	~LLCrashLoggerText(void) {}
-
-	virtual bool mainLoop();
-	virtual void updateApplication(const std::string& message = LLStringUtil::null);
-};
-
-
 #endif //LLCRASHLOGGER_H
-- 
cgit v1.2.3