feat: add detached flag to run in foreground with detached stdin (#5592)

* feat: add detached flag to run in foreground with detached stdin

* adjust contributors

* fix code style

* ref: move detached cin check to handleinput

* Update CONTRIBUTORS
This commit is contained in:
Super Ewald 2025-01-03 15:45:00 +01:00 committed by GitHub
parent 54269d78b2
commit 3c1cc4a513
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 1 deletions

View File

@ -90,6 +90,7 @@ Spongecade (Updated wiki links)
steve-nzr
structinf (xdot)
sweetgiorni
SuperEwald
Sxw1212
Taugeshtu
TheHyper45

View File

@ -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;

View File

@ -13,6 +13,7 @@
#include "OSSupport/MiniDumpWriter.h"
#include "OSSupport/SleepResolutionBooster.h"
#include "OSSupport/StartAsService.h"
#include <tclap/SwitchArg.h>
@ -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();

View File

@ -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;