diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenserver/config.cpp | 3 | ||||
| -rw-r--r-- | src/zenserver/config.h | 1 | ||||
| -rw-r--r-- | src/zenserver/main.cpp | 13 | ||||
| -rw-r--r-- | src/zenserver/xmake.lua | 28 |
4 files changed, 40 insertions, 5 deletions
diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index 867089ded..b430db629 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -611,6 +611,9 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) options.add_options()("sentry-allow-personal-info", "Allow personally identifiable information in sentry crash reports", cxxopts::value<bool>(ServerOptions.SentryAllowPII)->default_value("false")); + options.add_options()("detach", + "Indicate whether zenserver should detach from parent process group", + cxxopts::value<bool>(ServerOptions.Detach)->default_value("true")); // clang-format off options.add_options("logging") diff --git a/src/zenserver/config.h b/src/zenserver/config.h index 46fdd6fdf..4c9b9361c 100644 --- a/src/zenserver/config.h +++ b/src/zenserver/config.h @@ -157,6 +157,7 @@ struct ZenServerOptions bool IsFirstRun = false; bool NoSentry = false; bool SentryAllowPII = false; // Allow personally identifiable information in sentry crash reports + bool Detach = true; // Whether zenserver should detach from existing process group (Mac/Linux) bool ObjectStoreEnabled = false; bool NoConsoleOutput = false; // Control default use of stdout for diagnostics std::string Loggers[zen::logging::level::LogLevelCount]; diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index c27d4eb04..e6ecc3ce2 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -351,11 +351,6 @@ main(int argc, char* argv[]) } } -#if ZEN_PLATFORM_LINUX | ZEN_PLATFORM_MAC - // Detach ourselves from any parent process - setsid(); -#endif - signal(SIGINT, utils::SignalCallbackHandler); signal(SIGTERM, utils::SignalCallbackHandler); @@ -364,6 +359,14 @@ main(int argc, char* argv[]) ZenServerOptions ServerOptions; ParseCliOptions(argc, argv, ServerOptions); + if (ServerOptions.Detach) + { +#if ZEN_PLATFORM_LINUX | ZEN_PLATFORM_MAC + // Detach ourselves from any parent process + setsid(); +#endif + } + std::string_view DeleteReason; if (ServerOptions.IsCleanStart) diff --git a/src/zenserver/xmake.lua b/src/zenserver/xmake.lua index c42f305ee..a3d7aa124 100644 --- a/src/zenserver/xmake.lua +++ b/src/zenserver/xmake.lua @@ -68,3 +68,31 @@ target("zenserver") -- line below forces breakpad_client to be to the right of sentry_native add_syslinks("breakpad_client") end + + -- to work around some unfortunate Ctrl-C behaviour on Linux/Mac due to + -- our use of setsid() at startup we pass in `--no-detach` to zenserver + -- ensure that it recieves signals when the user requests termination + on_run(function(target) + -- the following is roughly cribbed from xmake/actions/run/xmake.lua + -- it would be nicer if we had the option of amending the arguments + -- via before_run for instance, but I can't figure out a way to do that + import("core.base.option") + + -- get the run directory of target + local rundir = target:rundir() + + -- get the absolute target file path + local targetfile = path.absolute(target:targetfile()) + + -- get run arguments + local args = table.wrap(option.get("arguments") or target:get("runargs")) + + table.insert(args, "--detach=false") + + -- debugging? + if option.get("debug") then + debugger.run(targetfile, args, {curdir = rundir}) + else + os.execv(targetfile, args, {curdir = rundir, detach = option.get("detach")}) + end + end) |