parent
0e3cee6287
commit
613f3651ea
5 changed files with 36 additions and 41 deletions
|
|
@ -8,7 +8,7 @@
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
#include "base/EventQueue.h"
|
#include "base/EventQueue.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "common/constants.h"
|
#include "common/Settings.h"
|
||||||
#include "deskflow/DaemonApp.h"
|
#include "deskflow/DaemonApp.h"
|
||||||
#include "deskflow/ipc/DaemonIpcServer.h"
|
#include "deskflow/ipc/DaemonIpcServer.h"
|
||||||
|
|
||||||
|
|
@ -80,7 +80,8 @@ int main(int argc, char **argv)
|
||||||
LOG_PRINT("%s v%s", QCoreApplication::applicationName().toStdString().c_str(), kDisplayVersion);
|
LOG_PRINT("%s v%s", QCoreApplication::applicationName().toStdString().c_str(), kDisplayVersion);
|
||||||
|
|
||||||
// Default log level to system setting (found in Registry).
|
// Default log level to system setting (found in Registry).
|
||||||
if (std::string logLevel = ARCH->setting("LogLevel"); logLevel != "") {
|
auto logLevel = Settings::value(Settings::Daemon::LogLevel).toString().toStdString();
|
||||||
|
if (logLevel != "") {
|
||||||
CLOG->setFilter(logLevel.c_str());
|
CLOG->setFilter(logLevel.c_str());
|
||||||
LOG_DEBUG("log level: %s", logLevel.c_str());
|
LOG_DEBUG("log level: %s", logLevel.c_str());
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +103,8 @@ int main(int argc, char **argv)
|
||||||
return kExitSuccess;
|
return kExitSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto ipcServer = new ipc::DaemonIpcServer(&app, DaemonApp::logFilename().c_str()); // NOSONAR - Qt managed
|
const auto ipcServer =
|
||||||
|
new ipc::DaemonIpcServer(&app, DaemonApp::logFilename().toStdString().c_str()); // NOSONAR - Qt managed
|
||||||
ipcServer->listen();
|
ipcServer->listen();
|
||||||
daemon.connectIpcServer(ipcServer);
|
daemon.connectIpcServer(ipcServer);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,13 @@ QVariant Settings::defaultValue(const QString &key)
|
||||||
if (key == Core::ProcessMode)
|
if (key == Core::ProcessMode)
|
||||||
return defaultProcessMode;
|
return defaultProcessMode;
|
||||||
|
|
||||||
|
if (key == Daemon::LogFile) {
|
||||||
|
return QStringLiteral("%1/%2").arg(instance()->settingsPath(), kDaemonLogFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == Daemon::Elevate)
|
||||||
|
return true;
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,13 @@ public:
|
||||||
inline static const auto ScreenName = QStringLiteral("core/screenName");
|
inline static const auto ScreenName = QStringLiteral("core/screenName");
|
||||||
inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
|
inline static const auto StartedBefore = QStringLiteral("core/startedBefore");
|
||||||
};
|
};
|
||||||
|
struct Daemon
|
||||||
|
{
|
||||||
|
inline static const auto Command = QStringLiteral("daemon/command");
|
||||||
|
inline static const auto Elevate = QStringLiteral("daemon/elevate");
|
||||||
|
inline static const auto LogFile = QStringLiteral("daemon/logFile");
|
||||||
|
inline static const auto LogLevel = QStringLiteral("daemon/logLevel");
|
||||||
|
};
|
||||||
struct Gui
|
struct Gui
|
||||||
{
|
{
|
||||||
inline static const auto Autohide = QStringLiteral("gui/autoHide");
|
inline static const auto Autohide = QStringLiteral("gui/autoHide");
|
||||||
|
|
@ -178,6 +185,9 @@ private:
|
||||||
, Settings::Core::ProcessMode
|
, Settings::Core::ProcessMode
|
||||||
, Settings::Core::ScreenName
|
, Settings::Core::ScreenName
|
||||||
, Settings::Core::StartedBefore
|
, Settings::Core::StartedBefore
|
||||||
|
, Settings::Daemon::Command
|
||||||
|
, Settings::Daemon::Elevate
|
||||||
|
, Settings::Daemon::LogFile
|
||||||
, Settings::Log::File
|
, Settings::Log::File
|
||||||
, Settings::Log::Level
|
, Settings::Log::Level
|
||||||
, Settings::Log::ToFile
|
, Settings::Log::ToFile
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,10 @@
|
||||||
|
|
||||||
#include "deskflow/DaemonApp.h"
|
#include "deskflow/DaemonApp.h"
|
||||||
|
|
||||||
#include "arch/XArch.h"
|
|
||||||
#include "base/IEventQueue.h"
|
#include "base/IEventQueue.h"
|
||||||
#include "base/Log.h"
|
#include "base/Log.h"
|
||||||
#include "base/log_outputters.h"
|
#include "base/log_outputters.h"
|
||||||
#include "common/constants.h"
|
#include "common/Settings.h"
|
||||||
#include "deskflow/App.h"
|
#include "deskflow/App.h"
|
||||||
#include "deskflow/ipc/DaemonIpcServer.h"
|
#include "deskflow/ipc/DaemonIpcServer.h"
|
||||||
|
|
||||||
|
|
@ -50,39 +49,21 @@ void DaemonApp::saveLogLevel(const QString &logLevel) const
|
||||||
{
|
{
|
||||||
LOG_DEBUG("log level changed: %s", logLevel.toUtf8().constData());
|
LOG_DEBUG("log level changed: %s", logLevel.toUtf8().constData());
|
||||||
CLOG->setFilter(logLevel.toUtf8().constData());
|
CLOG->setFilter(logLevel.toUtf8().constData());
|
||||||
|
Settings::setValue(Settings::Daemon::LogLevel, logLevel);
|
||||||
try {
|
|
||||||
// saves setting for next time the daemon starts.
|
|
||||||
ARCH->setting("LogLevel", logLevel.toStdString());
|
|
||||||
} catch (XArch &e) {
|
|
||||||
LOG_ERR("failed to save log level setting: %s", e.what());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonApp::setElevate(bool elevate)
|
void DaemonApp::setElevate(bool elevate)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("elevate value changed: %s", elevate ? "yes" : "no");
|
LOG_DEBUG("elevate value changed: %s", elevate ? "yes" : "no");
|
||||||
m_elevate = elevate;
|
m_elevate = elevate;
|
||||||
|
Settings::setValue(Settings::Daemon::Elevate, m_elevate);
|
||||||
try {
|
|
||||||
// saves setting for next time the daemon starts.
|
|
||||||
ARCH->setting("Elevate", std::string(elevate ? "1" : "0"));
|
|
||||||
} catch (XArch &e) {
|
|
||||||
LOG_ERR("failed to save elevate setting: %s", e.what());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonApp::setCommand(const QString &command)
|
void DaemonApp::setCommand(const QString &command)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("service command updated");
|
LOG_DEBUG("service command updated");
|
||||||
|
Settings::setValue(Settings::Daemon::Command, command);
|
||||||
m_command = command.toStdString();
|
m_command = command.toStdString();
|
||||||
|
|
||||||
try {
|
|
||||||
// saves setting for next time the daemon starts.
|
|
||||||
ARCH->setting("Command", command.toStdString());
|
|
||||||
} catch (XArch &e) {
|
|
||||||
LOG_ERR("failed to save command setting: %s", e.what());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonApp::applyWatchdogCommand() const
|
void DaemonApp::applyWatchdogCommand() const
|
||||||
|
|
@ -113,7 +94,10 @@ void DaemonApp::clearWatchdogCommand()
|
||||||
void DaemonApp::clearSettings() const
|
void DaemonApp::clearSettings() const
|
||||||
{
|
{
|
||||||
LOG_INFO("clearing daemon settings");
|
LOG_INFO("clearing daemon settings");
|
||||||
ARCH->clearSettings();
|
Settings::setValue(Settings::Daemon::Command, QVariant());
|
||||||
|
Settings::setValue(Settings::Daemon::Elevate, QVariant());
|
||||||
|
Settings::setValue(Settings::Daemon::LogFile, QVariant());
|
||||||
|
Settings::setValue(Settings::Daemon::LogLevel, QVariant());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonApp::connectIpcServer(const ipc::DaemonIpcServer *ipcServer) const
|
void DaemonApp::connectIpcServer(const ipc::DaemonIpcServer *ipcServer) const
|
||||||
|
|
@ -184,8 +168,8 @@ void DaemonApp::run(QThread &daemonThread)
|
||||||
#if SYSAPI_WIN32
|
#if SYSAPI_WIN32
|
||||||
m_pWatchdog = std::make_unique<MSWindowsWatchdog>(m_foreground, *m_pFileLogOutputter);
|
m_pWatchdog = std::make_unique<MSWindowsWatchdog>(m_foreground, *m_pFileLogOutputter);
|
||||||
|
|
||||||
std::string command = ARCH->setting("Command");
|
auto command = Settings::value(Settings::Daemon::Command).toString().toStdString();
|
||||||
bool elevate = ARCH->setting("Elevate") == "1";
|
bool elevate = Settings::value(Settings::Daemon::Elevate).toBool();
|
||||||
if (!command.empty()) {
|
if (!command.empty()) {
|
||||||
LOG_DEBUG("using last known command: %s", command.c_str());
|
LOG_DEBUG("using last known command: %s", command.c_str());
|
||||||
m_pWatchdog->setProcessConfig(command, elevate);
|
m_pWatchdog->setProcessConfig(command, elevate);
|
||||||
|
|
@ -253,17 +237,9 @@ int DaemonApp::mainLoop()
|
||||||
return kExitSuccess;
|
return kExitSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DaemonApp::logFilename()
|
QString DaemonApp::logFilename()
|
||||||
{
|
{
|
||||||
string logFilename;
|
return Settings::value(Settings::Daemon::LogFile).toString();
|
||||||
logFilename = ARCH->setting("LogFilename");
|
|
||||||
if (logFilename.empty()) {
|
|
||||||
logFilename = ARCH->getLogDirectory();
|
|
||||||
logFilename.append("/");
|
|
||||||
logFilename.append(kDaemonLogFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
return logFilename;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DaemonApp::setForeground()
|
void DaemonApp::setForeground()
|
||||||
|
|
@ -282,7 +258,7 @@ void DaemonApp::initLogging()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_pFileLogOutputter = new FileLogOutputter(logFilename().c_str()); // NOSONAR - Adopted by `Log`
|
m_pFileLogOutputter = new FileLogOutputter(logFilename().toStdString().c_str()); // NOSONAR - Adopted by `Log`
|
||||||
CLOG->insert(m_pFileLogOutputter);
|
CLOG->insert(m_pFileLogOutputter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ public:
|
||||||
void initLogging();
|
void initLogging();
|
||||||
void connectIpcServer(const deskflow::core::ipc::DaemonIpcServer *ipcServer) const;
|
void connectIpcServer(const deskflow::core::ipc::DaemonIpcServer *ipcServer) const;
|
||||||
|
|
||||||
static std::string logFilename();
|
static QString logFilename();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void daemonize();
|
void daemonize();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue