From 69eddaebbfc2ce67feb00a261694a55593d6442f Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 3 Dec 2025 20:33:34 -0800 Subject: [PATCH] Tools/pidof: Fixes FEXpidof after #5097 FEX argument will no longer exist in `/proc//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. --- Source/Tools/pidof/pidof.cpp | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Source/Tools/pidof/pidof.cpp b/Source/Tools/pidof/pidof.cpp index 848bd5cbe..def7ad987 100644 --- a/Source/Tools/pidof/pidof.cpp +++ b/Source/Tools/pidof/pidof.cpp @@ -19,6 +19,7 @@ namespace Config { bool SingleShot {}; bool SkipZombie {true}; bool DoNotDisplay {}; +bool AllFEX {}; std::string Separator {" "}; std::unordered_set OmitPids; std::unordered_set 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()) {