diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 5ecfa81da..0df6de2b0 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -90,6 +90,7 @@ Spongecade (Updated wiki links) steve-nzr structinf (xdot) sweetgiorni +SuperEwald Sxw1212 Taugeshtu TheHyper45 diff --git a/src/Root.cpp b/src/Root.cpp index 481c02f5b..131308043 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -212,6 +212,7 @@ bool cRoot::Run(cSettingsRepositoryInterface & a_OverridesRepo) m_StartTime = std::chrono::steady_clock::now(); HandleInput(); + s_StopEvent.Wait(); // Stop the server: @@ -998,7 +999,7 @@ AStringVector cRoot::GetPlayerTabCompletionMultiWorld(const AString & a_Text) void cRoot::HandleInput() { - if (g_RunAsService) + if (g_RunAsService || g_DetachedStdin) { // Ignore input when running as a service, cin was never opened in that case: return; diff --git a/src/main.cpp b/src/main.cpp index dd84e3be4..e39c9749f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ #include "OSSupport/MiniDumpWriter.h" #include "OSSupport/SleepResolutionBooster.h" #include "OSSupport/StartAsService.h" +#include @@ -22,6 +23,8 @@ bool g_ShouldLogCommIn; bool g_ShouldLogCommOut; bool g_RunAsService; +bool g_DetachedStdin; + @@ -44,9 +47,14 @@ static void ParseArguments(int argc, char ** argv, cMemorySettingsRepository & a TCLAP::SwitchArg noBufArg ("", "no-output-buffering", "Disable output buffering", cmd); TCLAP::SwitchArg noFileLogArg ("", "no-log-file", "Disable logging to file", cmd); TCLAP::SwitchArg runAsServiceArg ("d", "service", "Run as a service on Windows, or daemon on UNIX like systems", cmd); + TCLAP::SwitchArg runDetached ("", "detached", "Run with detached stdin (useful for container/docker)", cmd); cmd.parse(argc, argv); // Copy the parsed args' values into a settings repository: + if (runDetached.getValue()) + { + g_DetachedStdin = true; + } if (confArg.isSet()) { AString conf_file = confArg.getValue(); diff --git a/src/main.h b/src/main.h index 312fb051b..40e604f48 100644 --- a/src/main.h +++ b/src/main.h @@ -8,3 +8,6 @@ extern bool g_ShouldLogCommOut; /** If set to true, binary will attempt to run as a service. */ extern bool g_RunAsService; + +/** If set to true, binary runs in foreground without cstding handles */ +extern bool g_DetachedStdin;