mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-08 14:00:18 +02:00
This was causing problems in a typical use case of piping stdout/stderr to another application. So if FEXInterpreter was started, with stdout piped to another application, and FEXServer wasn't running so a new instance needed to be started. FEXServer would write a null to every pipe then close it. This includes the stdout that is being piped to the new application! This writing was legacy behaviour before FEX was properly listening to POLLHUP and is no longer necessary. Just remove the writing completely to fix this issue. Easiest test case was just `./Bin/FEXInterpreter `which ls` / | xxd | head -n 3` Returned: ``` $ ./Bin/FEXInterpreter `which ls` / | xxd | head -n 3 00000000: 0000 0000 6269 6e0a 6269 6e2e 7573 722d ....bin.bin.usr- 00000010: 6973 2d6d 6572 6765 640a 626f 6f74 0a64 is-merged.boot.d 00000020: 6576 0a65 7463 0a68 6f6d 650a 6c69 620a ev.etc.home.lib. ``` That first null shouldn't be there.
49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
// SPDX-License-Identifier: MIT
|
|
#include <cstdlib>
|
|
#include <dirent.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <vector>
|
|
|
|
namespace PipeScanner {
|
|
std::vector<int> IncomingPipes {};
|
|
|
|
// Scan and store any pipe files.
|
|
// This will capture all pipe files so needs to be executed early.
|
|
// This ensures we find any pipe files from execve for waiting FEXInterpreters.
|
|
void ScanForPipes() {
|
|
DIR* fd = opendir("/proc/self/fd");
|
|
if (fd) {
|
|
struct dirent* dir {};
|
|
do {
|
|
dir = readdir(fd);
|
|
if (dir) {
|
|
char* end {};
|
|
int open_fd = std::strtol(dir->d_name, &end, 8);
|
|
if (end != dir->d_name) {
|
|
struct stat stat {};
|
|
int result = fstat(open_fd, &stat);
|
|
if (result == -1) {
|
|
continue;
|
|
}
|
|
if (stat.st_mode & S_IFIFO) {
|
|
// Close any incoming pipes
|
|
IncomingPipes.emplace_back(open_fd);
|
|
}
|
|
}
|
|
}
|
|
} while (dir);
|
|
|
|
closedir(fd);
|
|
}
|
|
}
|
|
|
|
void ClosePipes() {
|
|
for (auto pipe : IncomingPipes) {
|
|
close(pipe);
|
|
}
|
|
IncomingPipes.clear();
|
|
}
|
|
} // namespace PipeScanner
|