mirror of https://github.com/nymea/nymea.git
Fix a potential crash in logging handlers
parent
2ca4b2f32f
commit
4d480f7c3b
|
|
@ -53,6 +53,7 @@
|
|||
namespace nymeaserver {
|
||||
|
||||
QList<QWebSocket*> DebugServerHandler::s_websocketClients;
|
||||
QMutex DebugServerHandler::s_loggingMutex;
|
||||
|
||||
DebugServerHandler::DebugServerHandler(QObject *parent) :
|
||||
QObject(parent)
|
||||
|
|
@ -572,6 +573,7 @@ void DebugServerHandler::logMessageHandler(QtMsgType type, const QMessageLogCont
|
|||
break;
|
||||
}
|
||||
|
||||
QMutexLocker locker(&s_loggingMutex);
|
||||
foreach (QWebSocket *client, s_websocketClients) {
|
||||
client->sendTextMessage(finalMessage);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include <QProcess>
|
||||
#include <QUrlQuery>
|
||||
#include <QWebSocketServer>
|
||||
#include <QMutex>
|
||||
|
||||
#include "debugreportgenerator.h"
|
||||
#include "servers/httpreply.h"
|
||||
|
|
@ -53,6 +54,7 @@ public:
|
|||
private:
|
||||
static QList<QWebSocket*> s_websocketClients;
|
||||
static void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message);
|
||||
static QMutex s_loggingMutex;
|
||||
|
||||
QWebSocketServer *m_websocketServer = nullptr;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ namespace nymeaserver {
|
|||
QList<ScriptEngine*> ScriptEngine::s_engines;
|
||||
QtMessageHandler ScriptEngine::s_upstreamMessageHandler;
|
||||
QLoggingCategory::CategoryFilter ScriptEngine::s_oldCategoryFilter = nullptr;
|
||||
QMutex ScriptEngine::s_loggerMutex;
|
||||
|
||||
ScriptEngine::ScriptEngine(ThingManager *deviceManager, QObject *parent) : QObject(parent),
|
||||
m_deviceManager(deviceManager)
|
||||
|
|
@ -446,6 +447,7 @@ void ScriptEngine::logMessageHandler(QtMsgType type, const QMessageLogContext &c
|
|||
return;
|
||||
}
|
||||
|
||||
QMutexLocker locker(&s_loggerMutex);
|
||||
// Copy the message to the script engine
|
||||
foreach (ScriptEngine *engine, s_engines) {
|
||||
engine->onScriptMessage(type, context, message);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include <QQmlEngine>
|
||||
#include <QJsonValue>
|
||||
#include <QLoggingCategory>
|
||||
#include <QMutex>
|
||||
|
||||
#include "integrations/thingmanager.h"
|
||||
#include "script.h"
|
||||
|
|
@ -111,6 +112,7 @@ private:
|
|||
static QLoggingCategory::CategoryFilter s_oldCategoryFilter;
|
||||
static void logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message);
|
||||
static void logCategoryFilter(QLoggingCategory *category);
|
||||
static QMutex s_loggerMutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QMutex>
|
||||
|
||||
QStringList s_nymeaLoggingCategories;
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ NYMEA_LOGGING_CATEGORY(dcI2C, "I2C")
|
|||
static QFile s_logFile;
|
||||
static bool s_useColors;
|
||||
static QList<QtMessageHandler> s_handlers;
|
||||
static QMutex s_loggerMutex;
|
||||
|
||||
static const char *const normal = "\033[0m";
|
||||
static const char *const warning = "\033[33m";
|
||||
|
|
@ -130,6 +132,7 @@ void nymeaLogMessageHandler(QtMsgType type, const QMessageLogContext &context, c
|
|||
}
|
||||
fflush(stdout);
|
||||
|
||||
QMutexLocker locker(&s_loggerMutex);
|
||||
if (s_logFile.isOpen()) {
|
||||
QTextStream textStream(&s_logFile);
|
||||
textStream << messageString << endl;
|
||||
|
|
|
|||
Loading…
Reference in New Issue