summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-07-06 17:17:17 +0200
committerStanislaw Halik <sthalik@misaki.pl>2023-07-06 17:34:18 +0200
commite0507257a41c29fa2e9ac28f36470023a72c39c6 (patch)
tree6885274b79adedd7df561b1347c814ce0a4bfd30
parent9d5219724d4eddf1e96a4e4a421f645069dd504a (diff)
compat: fix linux procps
We'll actually support both libprocps and libproc2. What a mess.
-rw-r--r--compat/process-list.hpp36
-rw-r--r--gui/CMakeLists.txt9
2 files changed, 42 insertions, 3 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>
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index bc9487b8..398223b3 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -11,7 +11,14 @@ target_link_libraries(${self}
if(APPLE)
target_link_libraries(${self} proc)
elseif(LINUX)
- otr_pkgconfig(${self} libproc2)
+ otr_pkgconfig_(has-libproc2 ${self} libproc2)
+ if(has-libproc2)
+ message(STATUS "!!!!! has libproc2")
+ target_compile_definitions(${self} PRIVATE -DOTR_HAS_LIBPROC2)
+ else()
+ message(STATUS "!!!!! no libproc2")
+ otr_pkgconfig(${self} libprocps)
+ endif()
endif()
if(NOT APPLE AND NOT WIN32)