mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-09 14:00:20 +02:00
Tools/pidof: Fixes FEXpidof after #5097
FEX argument will no longer exist in `/proc/<pid>/cmdline` after this PR. Ensure this tool still works. After #5097 is merged, one can use regular `pidof` for Linux applications, but this is still useful as it finds Wine applications running with FEX as well.
This commit is contained in:
1 file changed
+19
-19
@@ -19,6 +19,7 @@ namespace Config {
|
||||
bool SingleShot {};
|
||||
bool SkipZombie {true};
|
||||
bool DoNotDisplay {};
|
||||
bool AllFEX {};
|
||||
std::string Separator {" "};
|
||||
std::unordered_set<int64_t> OmitPids;
|
||||
std::unordered_set<std::string> Programs;
|
||||
@@ -65,6 +66,9 @@ void LoadOptions(int argc, char** argv) {
|
||||
}
|
||||
|
||||
for (const auto& Program : Parser.args()) {
|
||||
if (Program == "FEX") {
|
||||
AllFEX = true;
|
||||
}
|
||||
Programs.emplace(Program);
|
||||
}
|
||||
}
|
||||
@@ -239,14 +243,6 @@ int main(int argc, char** argv) {
|
||||
arg += strlen(arg) + 1;
|
||||
}
|
||||
|
||||
auto FindFEXArgument = [](auto& Path) -> int32_t {
|
||||
if (Path.ends_with("FEX")) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
struct ProgramPair {
|
||||
std::string_view ProgramPath;
|
||||
std::string_view ProgramFilename;
|
||||
@@ -303,20 +299,24 @@ int main(int argc, char** argv) {
|
||||
};
|
||||
|
||||
int32_t ProgramArg = -1;
|
||||
ProgramArg = FindFEXArgument(pid.exe_link);
|
||||
if (ProgramArg == -1) {
|
||||
ProgramArg = FindFEXArgument(Args[0]);
|
||||
if (pid.exe_link.ends_with("FEX")) {
|
||||
// Skip the first argument if it contains `FEX`, otherwise the application name begins at 0.
|
||||
ProgramArg = Args[0].ends_with("FEX") ? 1 : 0;
|
||||
}
|
||||
|
||||
// If matching all "FEX" instances then add to the matched list.
|
||||
if (ProgramArg != -1 && Config::AllFEX) {
|
||||
MatchedPIDs.emplace(pid.pid);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool IsWine = false;
|
||||
if (ProgramArg == -1) {
|
||||
// If we still haven't found a FEX path then this might be an arm64ec FEX application.
|
||||
// The only way to know for sure is the walk the mapped files of the process and check if FEX is mapped.
|
||||
if (FindWineFEXApplication(pid.pid, pid.exe_link, Args)) {
|
||||
// Search from the start.
|
||||
ProgramArg = 0;
|
||||
IsWine = true;
|
||||
}
|
||||
// If we still haven't found a FEX path then this might be an arm64ec FEX application.
|
||||
// The only way to know for sure is the walk the mapped files of the process and check if FEX is mapped.
|
||||
if (FindWineFEXApplication(pid.pid, pid.exe_link, Args)) {
|
||||
// Search from the start.
|
||||
ProgramArg = 0;
|
||||
IsWine = true;
|
||||
}
|
||||
|
||||
if (ProgramArg == -1 || ProgramArg >= Args.size()) {
|
||||
|
||||
Reference in new issue
Block a user