| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/helper/pmon/procpidsolver.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "procpidsolver.h"cxx . . $ `<file>/src/helper/pmon/procpidsolver.h`/ |
| 5 | |
| 6 | #include "common/fileutils.h"cxx . . $ `<file>/src/common/fileutils.h`/ |
| 7 | #include <algorithm> |
| 8 | #include <cctype> |
| 9 | #include <cstddef> |
| 10 | #include <system_error> |
| 11 | |
| 12 | stdcxx . . $ std/::stringcxx . . $ std/string# ProcPIDSolvercxx . . $ ProcPIDSolver#::appcxx . . $ ProcPIDSolver#app(7eb93f795f0defb3).(int PID) |
| 13 | { |
| 14 | auto const procPIDPath = procPath_cxx . . $ ProcPIDSolver#procPath_. /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). stdcxx . . $ std/filesystem/__cxx11/path#path(2f6c7066048c5333).::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(PID); |
| 15 | auto exeName = procExeFileNamecxx . . $ ProcPIDSolver#procExeFileName(e8724f73bdeef9de).(procPIDPath); |
| 16 | |
| 17 | // Handle wine apps. |
| 18 | if (wineExecutables_cxx . . $ ProcPIDSolver#wineExecutables_..findcxx . . $ std/set#find(5d7b472851d10a0f).(exeName) != wineExecutables_cxx . . $ ProcPIDSolver#wineExecutables_..cendcxx . . $ std/set#cend(3220b82c0db6d2a1).()) { |
| 19 | auto const entries = Utilscxx . . $ Utils/::Filecxx . . $ Utils/File/::readFileLinescxx . . $ Utils/File/readFileLines(951e54d16e2206f).(procPIDPath /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). "cmdline"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., |
| 20 | '\0'); |
| 21 | auto const wineExeName = wineAppNamecxx . . $ ProcPIDSolver#wineAppName(c704ec1904b9b1cc).(entries); |
| 22 | if (!wineExeName.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 23 | exeName =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). wineExeName; |
| 24 | } |
| 25 | |
| 26 | return exeNamecxx . . $ std/__cxx11/basic_string#basic_string(8f3aaafa33d05d0b).; |
| 27 | } |
| 28 | |
| 29 | stdcxx . . $ std/::stringcxx . . $ std/string# |
| 30 | ProcPIDSolvercxx . . $ ProcPIDSolver#::procExeFileNamecxx . . $ ProcPIDSolver#procExeFileName(e8724f73bdeef9de).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &procPIDPath) const |
| 31 | { |
| 32 | stdcxx . . $ std/::error_codecxx . . $ std/error_code# eccxx . . $ std/error_code#error_code(ced63f7c635d850d).; |
| 33 | return stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::read_symlinkcxx . . $ std/filesystem/read_symlink(d479473a5cb6f3a5).(procPIDPath /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). "exe"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., ec).filenamecxx . . $ std/filesystem/__cxx11/path#filename(159787a050b29eb0).(); |
| 34 | } |
| 35 | |
| 36 | stdcxx . . $ std/::stringcxx . . $ std/string# ProcPIDSolvercxx . . $ ProcPIDSolver#::lastComponentcxx . . $ ProcPIDSolver#lastComponent(ed3976f106e8bf8e).(stdcxx . . $ std/::stringcxx . . $ std/string# const &path) const |
| 37 | { |
| 38 | size_tcxx . . $ size_t# const pos = path.find_last_ofcxx . . $ std/__cxx11/basic_string#find_last_of(5ed402c22c298042).("\\/"); |
| 39 | if (pos == stdcxx . . $ std/::stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.) |
| 40 | return pathcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).; |
| 41 | |
| 42 | return path.substrcxx . . $ std/__cxx11/basic_string#substr(d59a03e0b0717fa0).(pos + 1); |
| 43 | } |
| 44 | |
| 45 | stdcxx . . $ std/::stringcxx . . $ std/string# ProcPIDSolvercxx . . $ ProcPIDSolver#::wineAppNamecxx . . $ ProcPIDSolver#wineAppName(c704ec1904b9b1cc).(stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::stringcxx . . $ std/string#> const &cmdline) const |
| 46 | { |
| 47 | for (auto const &entry : cmdline) { |
| 48 | |
| 49 | // skip wine executable files |
| 50 | stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const entryPathcxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).(entry); |
| 51 | if (entryPath.is_absolutecxx . . $ std/filesystem/__cxx11/path#is_absolute(3482b152b9333168).() && |
| 52 | wineExecutables_cxx . . $ ProcPIDSolver#wineExecutables_..findcxx . . $ std/set#find(5d7b472851d10a0f).(entryPath.filenamecxx . . $ std/filesystem/__cxx11/path#filename(159787a050b29eb0).()) != wineExecutables_cxx . . $ ProcPIDSolver#wineExecutables_..cendcxx . . $ std/set#cend(3220b82c0db6d2a1).()) |
| 53 | continue; |
| 54 | |
| 55 | // look for .exe extension |
| 56 | stdcxx . . $ std/::stringcxx . . $ std/string# extension = entryPath.extensioncxx . . $ std/filesystem/__cxx11/path#extension(159787a050b29eb0).(); |
| 57 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(extension.cbegincxx . . $ std/__cxx11/basic_string#cbegin(a865d278ca20c908).(), extension.cendcxx . . $ std/__cxx11/basic_string#cend(a865d278ca20c908).(), extension.begincxx . . $ std/__cxx11/basic_string#begin(fd29ebd65481b919).(), |
| 58 | ::tolower); |
| 59 | if (extension != ".exe") |
| 60 | break; |
| 61 | |
| 62 | return lastComponentcxx . . $ ProcPIDSolver#lastComponent(ed3976f106e8bf8e).(entry); |
| 63 | } |
| 64 | |
| 65 | return ""cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 66 | } |