Files
Ryan Houdek 8876047875 FEXServer: Fixes background startup
The problem here is that the pipe we used for telling FEXInterpreter
that the FEXServer is ready to accept connections was inherited by
erofsfuse or squashfuse. So the closing of the pipe from the FEXServer
side would leave a reference open in squashfuse or erofsfuse.

Fix this by setting FD_CLOEXEC on the pipe, but also pass the pipe FD
through an argument instead of scanning for all pipes.

Then once we execve the squashfuse/erofsfuse application, the FD isn't
inherited.

Fixes #4329
2025-02-09 23:59:32 -08:00

45 lines
1.6 KiB
C++

// SPDX-License-Identifier: MIT
#include "ArgumentLoader.h"
#include "Common/cpp-optparse/OptionParser.h"
#include "PipeScanner.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("-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);
}
return FEXOptions;
}
} // namespace FEXServer::Config