diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-07-06 17:17:17 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-07-06 17:34:18 +0200 |
commit | e0507257a41c29fa2e9ac28f36470023a72c39c6 (patch) | |
tree | 6885274b79adedd7df561b1347c814ce0a4bfd30 /compat | |
parent | 9d5219724d4eddf1e96a4e4a421f645069dd504a (diff) |
compat: fix linux procps
We'll actually support both libprocps and libproc2. What a mess.
Diffstat (limited to 'compat')
-rw-r--r-- | compat/process-list.hpp | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/compat/process-list.hpp b/compat/process-list.hpp index 26a5ceda..6d960610 100644 --- a/compat/process-list.hpp +++ b/compat/process-list.hpp @@ -131,9 +131,10 @@ static QStringList get_all_executable_names() #elif defined __linux__ -#include <libproc2/pids.h> #include <cerrno> +#ifdef OTR_HAS_LIBPROC2 +#include <libproc2/pids.h> template<typename = void> QStringList get_all_executable_names() { @@ -153,7 +154,7 @@ QStringList get_all_executable_names() // note, wine sets argv[0] so no parsing like in OSX case if (p_cmdline && p_cmdline[0] && p_cmdline[0][0] && - !(p_cmdline[0][0] == '-' && !p_cmdline[0][1])) + !(p_cmdline[0][0] == '-' && !p_cmdline[0][1])) { tmp = QString{p_cmdline[0]}; const int idx = std::max(tmp.lastIndexOf('\\'), tmp.lastIndexOf('/')); @@ -169,6 +170,37 @@ QStringList get_all_executable_names() return ret; } +#else +#include <proc/readproc.h> +#include <cerrno> + +template<typename = void> +QStringList get_all_executable_names() +{ + QStringList ret; + proc_t** procs = readproctab(PROC_FILLCOM); + if (procs == nullptr) + { + qDebug() << "readproctab" << errno; + return ret; + } + for (int i = 0; procs[i]; i++) + { + // note, wine sets argv[0] so no parsing like in OSX case + auto proc = procs[i]; + if (proc->cmdline && proc->cmdline[0]) + { + QString tmp(proc->cmdline[0]); + const int idx = std::max(tmp.lastIndexOf('\\'), tmp.lastIndexOf('/')); + tmp = tmp.mid(idx == -1 ? 0 : idx+1); + ret.append(tmp); + } + freeproc(procs[i]); + } + free(procs); + return ret; +} +#endif #else template<typename = void> |