mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 20:00:16 +02:00
This was a requested feature. To make sure that FEXServer is running and managed by a parent process, we need to have a way to tell FEXServer to keep alive without any FEX clients. The best way to do this is to pass FEXServer a Pipe (like FEX does when a client starts it), but instead of FEXServer signaling to FEXInterpreter that it's ready. FEXServer listens to the pipe to see if the management process is still alive. The expectation here is that the management process passes FEXServer the read end of a pipe, and when the management software is done (or gets killed by the kernel!) then the write end of the pipe is closed, and FEXServer naturally closes (As long as there's no FEX processes remaining).
48 lines
1.8 KiB
C++
48 lines
1.8 KiB
C++
// SPDX-License-Identifier: MIT
|
|
#include "ArgumentLoader.h"
|
|
#include "Common/cpp-optparse/OptionParser.h"
|
|
#include "PipeScanner.h"
|
|
#include "ProcessPipe.h"
|
|
|
|
#include "git_version.h"
|
|
|
|
#include <fmt/format.h>
|
|
|
|
namespace FEXServer::Config {
|
|
static fextl::string Version = "FEX-Emu (" GIT_DESCRIBE_STRING ") ";
|
|
|
|
FEXServerOptions Load(int argc, char** argv) {
|
|
FEXServerOptions FEXOptions {};
|
|
optparse::OptionParser Parser = optparse::OptionParser().version(Version);
|
|
|
|
Parser.add_option("-k", "--kill").action("store_true").set_default(false).help("Shutdown an already active FEXServer");
|
|
|
|
Parser.add_option("-f", "--foreground").action("store_true").set_default(false).help("Run this FEXServer in the foreground");
|
|
|
|
Parser.add_option("-p", "--persistent").action("store").type("int").set_default(0).set_optional_value(true).metavar("n").help("Make FEXServer persistent. Optional number of seconds");
|
|
|
|
Parser.add_option("-w", "--wait").action("store_true").set_default(false).help("Wait for the FEXServer to shutdown");
|
|
Parser.add_option("--wait_pipe").action("store").type("int").set_default(-1).set_optional_value(true);
|
|
Parser.add_option("--watch_fd").action("store").type("int").set_default(-1).set_optional_value(true).help("Adds FD to watch list of active processes");
|
|
|
|
Parser.add_option("-v").action("version").help("Version string");
|
|
|
|
optparse::Values Options = Parser.parse_args(argc, argv);
|
|
|
|
FEXOptions.Kill = Options.get("kill");
|
|
FEXOptions.Foreground = Options.get("foreground");
|
|
FEXOptions.Wait = Options.get("wait");
|
|
if (FEXOptions.Wait) {
|
|
FEXOptions.Foreground = true;
|
|
}
|
|
FEXOptions.PersistentTimeout = Options.get("persistent");
|
|
|
|
int WaitPipe = Options.get("wait_pipe");
|
|
if (WaitPipe != -1) {
|
|
PipeScanner::SetWaitPipe(WaitPipe);
|
|
}
|
|
ProcessPipe::SetWatchFD(Options.get("watch_fd"));
|
|
return FEXOptions;
|
|
}
|
|
} // namespace FEXServer::Config
|