From 657d4f5fa3da5a05295214772431d3ee140c44cf Mon Sep 17 00:00:00 2001 From: Imran Hussain Date: Tue, 30 Apr 2024 10:50:41 +0100 Subject: [PATCH] Fix linux daemon issue (#2572) * [linux][mangosd] fix a memory leak in console CLI * [mangosd][daemon] Don't start CLI when launched in daemon mode * [linux][daemon] don't change dirs -> don't break relative paths --- src/mangosd/CliRunnable.cpp | 3 +++ src/mangosd/Main.cpp | 2 +- src/mangosd/Master.cpp | 4 ++-- src/mangosd/Master.h | 2 +- src/shared/PosixDaemon.cpp | 6 ------ 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/mangosd/CliRunnable.cpp b/src/mangosd/CliRunnable.cpp index eea255d932d..012033acdb5 100644 --- a/src/mangosd/CliRunnable.cpp +++ b/src/mangosd/CliRunnable.cpp @@ -124,5 +124,8 @@ void CliRunnable::operator()() sWorld.QueueCliCommand(new CliCommandHolder(0, SEC_CONSOLE, nullptr, command.c_str(), &utf8print, &commandFinished)); } } + #ifndef WIN32 + free(command_str); + #endif } } diff --git a/src/mangosd/Main.cpp b/src/mangosd/Main.cpp index fd0a2153739..1b2ab6cbb28 100644 --- a/src/mangosd/Main.cpp +++ b/src/mangosd/Main.cpp @@ -216,7 +216,7 @@ extern int main(int argc, char **argv) // and run the 'Master' // TODO: Why do we need this 'Master'? Can't all of this be in the Main as for Realmd? - return sMaster.Run(); + return sMaster.Run(serviceDaemonMode); // at sMaster return function exist with codes // 0 - normal shutdown diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index 054672bce54..ecd1938e8cb 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -153,7 +153,7 @@ Master::~Master() } // Main function -int Master::Run() +int Master::Run(char serviceDaemonMode = '\0') { // worldd PID file creation std::string pidfile = sConfig.GetStringDefault("PidFile", ""); @@ -210,7 +210,7 @@ int Master::Run() #ifdef WIN32 if (sConfig.GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/) #else - if (sConfig.GetBoolDefault("Console.Enable", true)) + if (sConfig.GetBoolDefault("Console.Enable", true) && !serviceDaemonMode) #endif { // Launch CliRunnable thread diff --git a/src/mangosd/Master.h b/src/mangosd/Master.h index c2f29b82cfe..36c03c74394 100644 --- a/src/mangosd/Master.h +++ b/src/mangosd/Master.h @@ -35,7 +35,7 @@ class Master public: Master(); ~Master(); - int Run(); + int Run(char serviceDaemonMode); static volatile uint32 m_masterLoopCounter; static volatile bool m_handleSigvSignals; static void SigvSignalHandler(); diff --git a/src/shared/PosixDaemon.cpp b/src/shared/PosixDaemon.cpp index 15eb8f1034c..a8008330202 100644 --- a/src/shared/PosixDaemon.cpp +++ b/src/shared/PosixDaemon.cpp @@ -84,15 +84,9 @@ void startDaemon(uint32_t timeout) exit(EXIT_FAILURE); } - if ((chdir("/")) < 0) - { - exit(EXIT_FAILURE); - } - close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); - } void stopDaemon()