diff options
Diffstat (limited to 'indra/llcrashlogger/llcrashlock.cpp')
-rw-r--r-- | indra/llcrashlogger/llcrashlock.cpp | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/indra/llcrashlogger/llcrashlock.cpp b/indra/llcrashlogger/llcrashlock.cpp index 18d164abde..506232ab2a 100644 --- a/indra/llcrashlogger/llcrashlock.cpp +++ b/indra/llcrashlogger/llcrashlock.cpp @@ -1,4 +1,4 @@ -/** +/** * @file llformat.cpp * @date January 2007 * @brief string formatting utility @@ -6,21 +6,21 @@ * $LicenseInfo:firstyear=2007&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -33,7 +33,7 @@ #include "llsd.h" #include "llsdserialize.h" #include "llframetimer.h" -#include <boost/filesystem.hpp> +#include <boost/filesystem.hpp> #include <string> #include <iostream> #include <stdio.h> @@ -45,49 +45,49 @@ bool LLCrashLock::isProcessAlive(U32 pid, const std::string& pname) { - std::wstring wpname; - wpname = std::wstring(pname.begin(), pname.end()); - - HANDLE snapshot; - PROCESSENTRY32 pe32; - - bool matched = false; - - snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); - if (snapshot == INVALID_HANDLE_VALUE) - { - return false; - } - else - { - pe32.dwSize = sizeof(PROCESSENTRY32); - if (Process32First(snapshot, &pe32)) - { - do { - std::wstring wexecname = pe32.szExeFile; - std::string execname = std::string(wexecname.begin(), wexecname.end()); - if (!wpname.compare(pe32.szExeFile)) - { - if (pid == (U32)pe32.th32ProcessID) - { - matched = true; - break; - } - } - } while (Process32Next(snapshot, &pe32)); - } - } - - CloseHandle(snapshot); - return matched; + std::wstring wpname; + wpname = std::wstring(pname.begin(), pname.end()); + + HANDLE snapshot; + PROCESSENTRY32 pe32; + + bool matched = false; + + snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (snapshot == INVALID_HANDLE_VALUE) + { + return false; + } + else + { + pe32.dwSize = sizeof(PROCESSENTRY32); + if (Process32First(snapshot, &pe32)) + { + do { + std::wstring wexecname = pe32.szExeFile; + std::string execname = std::string(wexecname.begin(), wexecname.end()); + if (!wpname.compare(pe32.szExeFile)) + { + if (pid == (U32)pe32.th32ProcessID) + { + matched = true; + break; + } + } + } while (Process32Next(snapshot, &pe32)); + } + } + + CloseHandle(snapshot); + return matched; } #else //Everyone Else bool LLCrashLock::isProcessAlive(U32 pid, const std::string& pname) { - //Will boost.process ever become a reality? + //Will boost.process ever become a reality? std::stringstream cmd; - + cmd << "pgrep '" << pname << "' | grep '^" << pid << "$'"; return (!system(cmd.str().c_str())); } @@ -101,46 +101,46 @@ LLCrashLock::LLCrashLock() : mCleanUp(true), mWaitingPID(0) void LLCrashLock::setCleanUp(bool cleanup) { mCleanUp = cleanup; //Allow cleanup to be disabled for debugging. -} +} LLSD LLCrashLock::getLockFile(std::string filename) { - LLSD lock_sd = LLSD::emptyMap(); - - llifstream ifile(filename.c_str()); - - if (ifile.is_open()) - { + LLSD lock_sd = LLSD::emptyMap(); + + llifstream ifile(filename.c_str()); + + if (ifile.is_open()) + { LLSDSerialize::fromXML(lock_sd, ifile); - ifile.close(); - } + ifile.close(); + } return lock_sd; } bool LLCrashLock::putLockFile(std::string filename, const LLSD& data) -{ +{ bool result = true; llofstream ofile(filename.c_str()); - - if (!LLSDSerialize::toXML(data,ofile)) - { + + if (!LLSDSerialize::toXML(data,ofile)) + { result=false; - } - ofile.close(); + } + ofile.close(); return result; } bool LLCrashLock::requestMaster( F32 timeout ) { - if (mMaster.empty()) - { - mMaster = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, + if (mMaster.empty()) + { + mMaster = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "crash_master.lock"); - } + } LLSD lock_sd=getLockFile(mMaster); - + if (lock_sd.has("pid")) { mWaitingPID = lock_sd["pid"].asInteger(); @@ -150,8 +150,8 @@ bool LLCrashLock::requestMaster( F32 timeout ) return false; } } - - U32 pid = getpid(); + + U32 pid = getpid(); lock_sd["pid"] = (LLSD::Integer)pid; return putLockFile(mMaster,lock_sd); } @@ -179,10 +179,10 @@ void LLCrashLock::releaseMaster() LLSD LLCrashLock::getProcessList() { if (mDumpTable.empty()) - { - mDumpTable= gDirUtilp->getExpandedFilename(LL_PATH_LOGS, - "crash_table.lock"); - } + { + mDumpTable= gDirUtilp->getExpandedFilename(LL_PATH_LOGS, + "crash_table.lock"); + } return getLockFile(mDumpTable); } @@ -190,21 +190,21 @@ LLSD LLCrashLock::getProcessList() bool LLCrashLock::fileExists(std::string filename) { #ifdef LL_WINDOWS // or BOOST_WINDOWS_API - boost::filesystem::path file_path(utf8str_to_utf16str(filename)); + boost::filesystem::path file_path(utf8str_to_utf16str(filename)); #else - boost::filesystem::path file_path(filename); + boost::filesystem::path file_path(filename); #endif - return boost::filesystem::exists(file_path); + return boost::filesystem::exists(file_path); } void LLCrashLock::cleanupProcess(std::string proc_dir) { #ifdef LL_WINDOWS // or BOOST_WINDOWS_API - boost::filesystem::path dir_path(utf8str_to_utf16str(proc_dir)); + boost::filesystem::path dir_path(utf8str_to_utf16str(proc_dir)); #else - boost::filesystem::path dir_path(proc_dir); + boost::filesystem::path dir_path(proc_dir); #endif - boost::filesystem::remove_all(dir_path); + boost::filesystem::remove_all(dir_path); } bool LLCrashLock::putProcessList(const LLSD& proc_sd) |