From 76eaa9f89348403ee7a7d1776b97b72702d40241 Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Fri, 21 Jun 2024 13:41:57 +0300 Subject: [PATCH] Revert "Fix linux daemon issue (#2572)" This reverts commit 657d4f5fa3da5a05295214772431d3ee140c44cf. --- 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, 10 insertions(+), 7 deletions(-) diff --git a/src/mangosd/CliRunnable.cpp b/src/mangosd/CliRunnable.cpp index 012033acdb5..eea255d932d 100644 --- a/src/mangosd/CliRunnable.cpp +++ b/src/mangosd/CliRunnable.cpp @@ -124,8 +124,5 @@ 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 1b2ab6cbb28..fd0a2153739 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(serviceDaemonMode); + return sMaster.Run(); // at sMaster return function exist with codes // 0 - normal shutdown diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index ecd1938e8cb..054672bce54 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -153,7 +153,7 @@ Master::~Master() } // Main function -int Master::Run(char serviceDaemonMode = '\0') +int Master::Run() { // worldd PID file creation std::string pidfile = sConfig.GetStringDefault("PidFile", ""); @@ -210,7 +210,7 @@ int Master::Run(char serviceDaemonMode = '\0') #ifdef WIN32 if (sConfig.GetBoolDefault("Console.Enable", true) && (m_ServiceStatus == -1)/* need disable console in service mode*/) #else - if (sConfig.GetBoolDefault("Console.Enable", true) && !serviceDaemonMode) + if (sConfig.GetBoolDefault("Console.Enable", true)) #endif { // Launch CliRunnable thread diff --git a/src/mangosd/Master.h b/src/mangosd/Master.h index 36c03c74394..c2f29b82cfe 100644 --- a/src/mangosd/Master.h +++ b/src/mangosd/Master.h @@ -35,7 +35,7 @@ class Master public: Master(); ~Master(); - int Run(char serviceDaemonMode); + int Run(); 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 a8008330202..15eb8f1034c 100644 --- a/src/shared/PosixDaemon.cpp +++ b/src/shared/PosixDaemon.cpp @@ -84,9 +84,15 @@ 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()