From 680934812598d2c9116303f3245e7a9d60ff58bf Mon Sep 17 00:00:00 2001 From: Aura Linden Date: Tue, 3 Dec 2013 17:06:06 -0800 Subject: Creating a cleaner branch --- indra/llcrashlogger/llcrashlogger.cpp | 282 +++++++++++++++++++++++++++------- 1 file changed, 223 insertions(+), 59 deletions(-) (limited to 'indra/llcrashlogger/llcrashlogger.cpp') diff --git a/indra/llcrashlogger/llcrashlogger.cpp b/indra/llcrashlogger/llcrashlogger.cpp index fb2d43e3b0..baff29e818 100755 --- a/indra/llcrashlogger/llcrashlogger.cpp +++ b/indra/llcrashlogger/llcrashlogger.cpp @@ -23,12 +23,14 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ + #include #include #include #include #include "llcrashlogger.h" +#include "llcrashlock.h" #include "linden_common.h" #include "llstring.h" #include "indra_constants.h" // CRASH_BEHAVIOR_... @@ -43,6 +45,8 @@ #include "llhttpclient.h" #include "llsdserialize.h" #include "llproxy.h" + +extern void flog(std::string msg); //SPATTERS LLPumpIO* gServicePump; BOOL gBreak = false; @@ -61,7 +65,7 @@ public: } virtual void result(const LLSD& content) - { + { gBreak = true; gSent = true; } @@ -74,8 +78,6 @@ LLCrashLogger::LLCrashLogger() : mSentCrashLogs(false), mCrashHost("") { - // Set up generic error handling - setupErrorHandling(); } LLCrashLogger::~LLCrashLogger() @@ -137,19 +139,70 @@ std::string getStartupStateFromLog(std::string& sllog) return startup_state; } -void LLCrashLogger::gatherFiles() +bool LLCrashLogger::readDebugFromXML(LLSD& dest, const std::string& filename ) { - updateApplication("Gathering logs..."); - - // Figure out the filename of the debug log - std::string db_file_name = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,"debug_info.log"); - std::ifstream debug_log_file(db_file_name.c_str()); - + std::string db_file_name = gDirUtilp->getExpandedFilename(LL_PATH_DUMP,filename); + std::ifstream debug_log_file(db_file_name.c_str()); + // Look for it in the debug_info.log file if (debug_log_file.is_open()) { - LLSDSerialize::fromXML(mDebugLog, debug_log_file); + LLSDSerialize::fromXML(dest, debug_log_file); + debug_log_file.close(); + return true; + } + return false; +} + +void LLCrashLogger::mergeLogs( LLSD src_sd ) +{ + LLSD::map_iterator iter = src_sd.beginMap(); + LLSD::map_iterator end = src_sd.endMap(); + for( ; iter != end; ++iter) + { + mDebugLog[iter->first] = iter->second; + } +} + +bool LLCrashLogger::readMinidump(std::string minidump_path) +{ + size_t length=0; + + flog("SPATTERS 1"); + flog (minidump_path); + + std::ifstream minidump_stream(minidump_path.c_str(), std::ios_base::in | std::ios_base::binary); + if(minidump_stream.is_open()) + { + minidump_stream.seekg(0, std::ios::end); + length = (size_t)minidump_stream.tellg(); + minidump_stream.seekg(0, std::ios::beg); + + LLSD::Binary data; + data.resize(length); + + minidump_stream.read(reinterpret_cast(&(data[0])),length); + minidump_stream.close(); + + mCrashInfo["Minidump"] = data; + } + return (length>0?true:false); +} +void LLCrashLogger::gatherFiles() +{ + updateApplication("Gathering logs..."); + + LLSD static_sd; + LLSD dynamic_sd; + + bool has_logs = readDebugFromXML( static_sd, "static_debug_info.log" ); + has_logs |= readDebugFromXML( dynamic_sd, "dynamic_debug_info.log" ); + + if ( has_logs ) + { + mDebugLog = static_sd; + mergeLogs(dynamic_sd); mCrashInPreviousExec = mDebugLog["CrashNotHandled"].asBoolean(); mFileMap["SecondLifeLog"] = mDebugLog["SLLog"].asString(); @@ -214,7 +267,7 @@ void LLCrashLogger::gatherFiles() mAltCrashHost = "https://login.agni.lindenlab.com:12043/crash/report"; mCrashInfo["DebugLog"] = mDebugLog; - mFileMap["StatsLog"] = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,"stats.log"); + mFileMap["StatsLog"] = gDirUtilp->getExpandedFilename(LL_PATH_DUMP,"stats.log"); updateApplication("Encoding files..."); @@ -242,32 +295,56 @@ void LLCrashLogger::gatherFiles() mCrashInfo[(*itr).first] = LLStringFn::strip_invalid_xml(rawstr_to_utf8(crash_info)); } + std::string minidump_path; // Add minidump as binary. - std::string minidump_path = mDebugLog["MinidumpPath"]; - if(minidump_path != "") + bool has_minidump = mDebugLog.has("MinidumpPath"); + + if (has_minidump) { - std::ifstream minidump_stream(minidump_path.c_str(), std::ios_base::in | std::ios_base::binary); - if(minidump_stream.is_open()) - { - minidump_stream.seekg(0, std::ios::end); - size_t length = (size_t)minidump_stream.tellg(); - minidump_stream.seekg(0, std::ios::beg); - - LLSD::Binary data; - data.resize(length); - - minidump_stream.read(reinterpret_cast(&(data[0])),length); - minidump_stream.close(); - - mCrashInfo["Minidump"] = data; - } + minidump_path = mDebugLog["MinidumpPath"].asString(); + flog ("SPATTERS minidump name is"); + flog (minidump_path); + } + + if (has_minidump) + { + has_minidump = readMinidump(minidump_path); } - mCrashInfo["DebugLog"].erase("MinidumpPath"); + + if (!has_minidump) //Viewer was probably so hosed it couldn't write remaining data. Try brute force. + { + //Look for a filename at least 30 characters long in the dump dir which contains the characters MDMP as the first 4 characters in the file. + typedef std::vector vec; + flog("Failed to read minidump."); + std::string pathname = gDirUtilp->getExpandedFilename(LL_PATH_DUMP,""); + vec file_vec = gDirUtilp->getFilesInDir(pathname); + for(vec::const_iterator iter=file_vec.begin(); iter!=file_vec.end(); ++iter) + { + if ( ( iter->length() > 30 ) && (iter->rfind(".log") != (iter->length()-4) ) ) + { + std::string fullname = pathname + *iter; + std::ifstream fdat( fullname.c_str(), std::ifstream::binary); + if (fdat) + { + char buf[5]; + fdat.read(buf,4); + fdat.close(); + if (!strncmp(buf,"MDMP",4)) + { + minidump_path = *iter; + has_minidump = readMinidump(minidump_path); + mDebugLog["MinidumpPath"] = fullname; + flog ("Picked up minidump on the rebound."); + flog (fullname); + } + } + } + } + } } LLSD LLCrashLogger::constructPostData() { - LLSD ret; return mCrashInfo; } @@ -337,39 +414,110 @@ bool LLCrashLogger::runCrashLogPost(std::string host, LLSD data, std::string msg return gSent; } -bool LLCrashLogger::sendCrashLogs() +bool LLCrashLogger::sendCrashLog(std::string dump_dir) { + gDirUtilp->setDumpDir( dump_dir ); + + std::string dump_path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, + "SecondLifeCrashReport"); + std::string report_file = dump_path + ".log"; + gatherFiles(); - + LLSD post_data; post_data = constructPostData(); - + updateApplication("Sending reports..."); - std::string dump_path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, - "SecondLifeCrashReport"); - std::string report_file = dump_path + ".log"; - std::ofstream out_file(report_file.c_str()); LLSDSerialize::toPrettyXML(post_data, out_file); out_file.close(); - + bool sent = false; - + //*TODO: Translate if(mCrashHost != "") { sent = runCrashLogPost(mCrashHost, post_data, std::string("Sending to server"), 3, 5); } - + if(!sent) { sent = runCrashLogPost(mAltCrashHost, post_data, std::string("Sending to alternate server"), 3, 5); } - + mSentCrashLogs = sent; + + return sent; +} - return true; +bool LLCrashLogger::sendCrashLogs() +{ + + //pertinent code from below moved into a subroutine. + LLSD locks = mKeyMaster.getProcessList(); + LLSD newlocks = LLSD::emptyArray(); + + LLSD opts = getOptionData(PRIORITY_COMMAND_LINE); + LLSD rec; + + if ( opts.has("pid") && opts.has("dumpdir") && opts.has("procname") ) + { + rec["pid"]=opts["pid"]; + rec["dumpdir"]=opts["dumpdir"]; + rec["procname"]=opts["procname"]; +#if LL_WINDOWS + locks.append(rec); +#endif + } + + if (locks.isArray()) + { + for (LLSD::array_iterator lock=locks.beginArray(); + lock !=locks.endArray(); + ++lock) + { + if ( (*lock).has("pid") && (*lock).has("dumpdir") && (*lock).has("procname") ) + { + if ( mKeyMaster.isProcessAlive( (*lock)["pid"].asInteger(), (*lock)["procname"].asString() ) ) + { + newlocks.append(*lock); + } + else + { + //TODO: This is a hack but I didn't want to include boost in another file or retest everything related to lldir + if (LLCrashLock::fileExists((*lock)["dumpdir"].asString())) + { + //the viewer cleans up the log directory on clean shutdown + //but is ignorant of the locking table. + if (!sendCrashLog((*lock)["dumpdir"].asString())) + { + newlocks.append(*lock); //Failed to send log so don't delete it. + } + else + { + //mCrashInfo["DebugLog"].erase("MinidumpPath"); + + //SPATTERS mKeyMaster.cleanupProcess((*lock)["dumpdir"].asString()); + } + } + } + } + else + { + llwarns << "Discarding corrupted entry from lock table." << llendl; + } + } + } +#if !LL_WINDOWS + if (rec) + { + newlocks.append(rec); + } +#endif + + mKeyMaster.putProcessList(newlocks); + return true; } void LLCrashLogger::updateApplication(const std::string& message) @@ -391,42 +539,58 @@ bool LLCrashLogger::init() // Default to the product name "Second Life" (this is overridden by the -name argument) mProductName = "Second Life"; - // Rename current log file to ".old" + // Handle locking + bool locked = mKeyMaster.requestMaster(); //Request maser locking file. wait time is defaulted to 300S + + while (!locked && mKeyMaster.isWaiting()) + { +#if LL_WINDOWS + Sleep(1000); +#else + sleep(1); +#endif + locked = mKeyMaster.checkMaster(); + } + + if (!locked) + { + llwarns << "Unable to get master lock. Another crash reporter may be hung." << llendl; + return false; + } + + // 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()); +#if LL_WINDOWS + LLAPRFile::remove(old_log_file); +#endif + + LLFile::rename(log_file.c_str(), old_log_file.c_str()); + // Set the log file to crashreport.log LLError::logToFile(log_file); - - mCrashSettings.declareS32("CrashSubmitBehavior", CRASH_BEHAVIOR_ALWAYS_SEND, + + 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(); - + // If user doesn't want to send, bail out if (mCrashBehavior == CRASH_BEHAVIOR_NEVER_SEND) { llinfos << "Crash behavior is never_send, quitting" << llendl; return false; } - + gServicePump = new LLPumpIO(gAPRPoolp); gServicePump->prime(gAPRPoolp); LLHTTPClient::setPump(*gServicePump); - - //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"); - LLAPRFile::remove( marker_file ); - } - + return true; } -- cgit v1.2.3