Some practical improvements for the report handling

This commit is contained in:
kaetemi 2015-03-06 21:07:12 +01:00
parent c5a40c2616
commit 4afe23c6e3
6 changed files with 30 additions and 11 deletions

View file

@ -347,7 +347,7 @@ std::string formatThousands(const std::string& s);
/// This function executes a program in the background and returns instantly (used for example to launch services in AES). /// This function executes a program in the background and returns instantly (used for example to launch services in AES).
/// The program will be launched in the current directory /// The program will be launched in the current directory
bool launchProgram (const std::string &programName, const std::string &arguments); bool launchProgram (const std::string &programName, const std::string &arguments, bool log = true);
/// This function kills a program using his pid (on unix, it uses the kill() POSIX function) /// This function kills a program using his pid (on unix, it uses the kill() POSIX function)
bool killProgram(uint32 pid); bool killProgram(uint32 pid);

View file

@ -77,6 +77,10 @@ public:
/// Get desktop current color depth without using UDriver. /// Get desktop current color depth without using UDriver.
static uint getCurrentColorDepth(); static uint getCurrentColorDepth();
/// Detect whether the current process is a windowed application. Return true if definitely yes, false if unknown
static bool detectWindowedApplication();
}; };
} // NLMISC } // NLMISC

View file

@ -667,7 +667,7 @@ bool abortProgram(uint32 pid)
#endif #endif
} }
bool launchProgram (const std::string &programName, const std::string &arguments) bool launchProgram(const std::string &programName, const std::string &arguments, bool log)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
@ -719,6 +719,7 @@ bool launchProgram (const std::string &programName, const std::string &arguments
{ {
LPVOID lpMsgBuf; LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
if (log)
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf); nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf);
LocalFree(lpMsgBuf); LocalFree(lpMsgBuf);
CloseHandle( pi.hProcess ); CloseHandle( pi.hProcess );
@ -776,6 +777,7 @@ bool launchProgram (const std::string &programName, const std::string &arguments
if (status == -1) if (status == -1)
{ {
char *err = strerror (errno); char *err = strerror (errno);
if (log)
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err); nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err);
} }
else if (status == 0) else if (status == 0)
@ -796,6 +798,7 @@ bool launchProgram (const std::string &programName, const std::string &arguments
return true; return true;
} }
#else #else
if (log)
nlwarning ("LAUNCH: launchProgram() not implemented"); nlwarning ("LAUNCH: launchProgram() not implemented");
#endif #endif

View file

@ -53,6 +53,7 @@
#include "nel/misc/path.h" #include "nel/misc/path.h"
#include "nel/misc/variable.h" #include "nel/misc/variable.h"
#include "nel/misc/system_info.h" #include "nel/misc/system_info.h"
#include "nel/misc/system_utils.h"
#define NL_NO_DEBUG_FILES 1 #define NL_NO_DEBUG_FILES 1
@ -1223,10 +1224,8 @@ void createDebug (const char *logPath, bool logInFile, bool eraseLastLog)
#endif // LOG_IN_FILE #endif // LOG_IN_FILE
DefaultMemDisplayer = new CMemDisplayer ("DEFAULT_MD"); DefaultMemDisplayer = new CMemDisplayer ("DEFAULT_MD");
#ifdef NL_OS_WINDOWS if (NLMISC::CSystemUtils::detectWindowedApplication())
if (GetConsoleWindow() == NULL)
INelContext::getInstance().setWindowedApplication(true); INelContext::getInstance().setWindowedApplication(true);
#endif
initDebug2(logInFile); initDebug2(logInFile);

View file

@ -25,6 +25,7 @@
#include "nel/misc/report.h" #include "nel/misc/report.h"
#include "nel/misc/path.h" #include "nel/misc/path.h"
#include "nel/misc/file.h" #include "nel/misc/file.h"
#include "nel/misc/system_utils.h"
#ifdef DEBUG_NEW #ifdef DEBUG_NEW
#define new DEBUG_NEW #define new DEBUG_NEW
@ -102,8 +103,9 @@ TReportResult report(const std::string &title, const std::string &subject, const
} }
} }
if (INelContext::isContextInitialised() if (((INelContext::isContextInitialised()
&& INelContext::getInstance().isWindowedApplication() && INelContext::getInstance().isWindowedApplication())
|| CSystemUtils::detectWindowedApplication())
&& CFile::isExists(NL_CRASH_REPORT_TOOL)) && CFile::isExists(NL_CRASH_REPORT_TOOL))
{ {
std::stringstream params; std::stringstream params;
@ -151,7 +153,8 @@ TReportResult report(const std::string &title, const std::string &subject, const
} }
else else
{ {
NLMISC::launchProgram(NL_CRASH_REPORT_TOOL, paramsStr); // FIXME: Don't use this function, it uses logging, etc, so may loop infinitely! NLMISC::launchProgram(NL_CRASH_REPORT_TOOL, paramsStr,
NL_DEBUG_REPORT ? INelContext::isContextInitialised() : false); // Only log if required, avoid infinite loop
return defaultResult; return defaultResult;
} }
} }

View file

@ -355,4 +355,14 @@ uint CSystemUtils::getCurrentColorDepth()
return depth; return depth;
} }
/// Detect whether the current process is a windowed application. Return true if definitely yes, false if unknown
bool CSystemUtils::detectWindowedApplication()
{
#ifdef NL_OS_WINDOWS
if (GetConsoleWindow() == NULL)
return true;
#endif
return false;
}
} // NLMISC } // NLMISC