Some practical improvements for the report handling

--HG--
branch : develop
This commit is contained in:
kaetemi 2015-03-06 21:07:12 +01:00
parent 163abf31b8
commit 29f42ed5ab
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).
/// 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)
bool killProgram(uint32 pid);

View file

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

View file

@ -667,7 +667,7 @@ bool abortProgram(uint32 pid)
#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
@ -719,7 +719,8 @@ bool launchProgram (const std::string &programName, const std::string &arguments
{
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);
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError (), lpMsgBuf);
if (log)
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), GetLastError(), lpMsgBuf);
LocalFree(lpMsgBuf);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
@ -776,7 +777,8 @@ bool launchProgram (const std::string &programName, const std::string &arguments
if (status == -1)
{
char *err = strerror (errno);
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err);
if (log)
nlwarning("LAUNCH: Failed launched '%s' with arg '%s' err %d: '%s'", programName.c_str(), arguments.c_str(), errno, err);
}
else if (status == 0)
{
@ -796,7 +798,8 @@ bool launchProgram (const std::string &programName, const std::string &arguments
return true;
}
#else
nlwarning ("LAUNCH: launchProgram() not implemented");
if (log)
nlwarning ("LAUNCH: launchProgram() not implemented");
#endif
return false;

View file

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

View file

@ -25,6 +25,7 @@
#include "nel/misc/report.h"
#include "nel/misc/path.h"
#include "nel/misc/file.h"
#include "nel/misc/system_utils.h"
#ifdef DEBUG_NEW
#define new DEBUG_NEW
@ -102,8 +103,9 @@ TReportResult report(const std::string &title, const std::string &subject, const
}
}
if (INelContext::isContextInitialised()
&& INelContext::getInstance().isWindowedApplication()
if (((INelContext::isContextInitialised()
&& INelContext::getInstance().isWindowedApplication())
|| CSystemUtils::detectWindowedApplication())
&& CFile::isExists(NL_CRASH_REPORT_TOOL))
{
std::stringstream params;
@ -151,7 +153,8 @@ TReportResult report(const std::string &title, const std::string &subject, const
}
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;
}
}

View file

@ -355,4 +355,14 @@ uint CSystemUtils::getCurrentColorDepth()
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