From 9a0cb353b8a19b186fe3c9138e058779cd53bd33 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 13 Aug 2015 10:53:19 +0200 Subject: initial broken multi-platform process lister --- opentrack-compat/process-list.hpp | 105 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 opentrack-compat/process-list.hpp (limited to 'opentrack-compat') diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp new file mode 100755 index 00000000..a00cbb17 --- /dev/null +++ b/opentrack-compat/process-list.hpp @@ -0,0 +1,105 @@ +#pragma once + +#include +#include + +#if defined _WIN32 + +#include +#include + +template +static QStringList get_all_executable_names() +{ + QStringList ret; + HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (h == INVALID_HANDLE_VALUE) + return ret; + + PROCESSENTRY32 e; + e.dwSize = sizeof(e); + + if (Process32First(h, &e) != TRUE) + { + CloseHandle(h); + return ret; + } + + do { + ret.append(e.szExeFile); + } while (Process32Next(h, &e) == TRUE); + + CloseHandle(h); + + return ret; +} +#elif defined __APPLE__ +#include +#include +#include +#include + +// link to libproc +template +static QStringList get_all_executable_names() +{ + QStringList ret; + std::vector vec; + + while (true) + { + int numproc = proc_listpids(PROC_ALL_PIDS, 0, nullptr, 0); + if (numproc == -1) + { + qDebug() << "numproc failed" << errno; + break; + } + vec.resize(numproc); + int cnt = proc_listpids(PROC_ALL_PIDS, 0, &vec[0], sizeof(int) * numproc); + if (cnt <= numproc) + { + char name[2 * 2 * MAXCOMLEN + 1]; + for (int i = 0; i < cnt; i++) + { + int ret = proc_name(vec[i], name, sizeof(name)-1); + if (ret <= 0) + continue; + name[ret] = '\0'; + ret.append(name); + } + return ret; + } + } +} + +#elif defined __linux + +// link to procps +#include +#include +template +static 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++) + { + auto& proc = *procs[i]; + ret.append(proc.cmd); + } + freeproctab(procs); + return ret; +} + +#else +template +static QStringList get_all_executable_names() +{ + return QStringList(); +} +#endif -- cgit v1.2.3 From 413e6fef09190b0ddc1a110415d964f88f332655 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 13 Aug 2015 13:00:38 +0200 Subject: fixed process detector for OSX Issue: #181 --- CMakeLists.txt | 5 +++ opentrack-compat/process-list.hpp | 68 +++++++++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 9 deletions(-) (limited to 'opentrack-compat') diff --git a/CMakeLists.txt b/CMakeLists.txt index 65c7c81d..18e2a9cd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -509,6 +509,11 @@ if(CMAKE_SYSTEM STREQUAL LINUX) link_libraries(rt) endif() +if(APPLE) + # for process detector + target_link_libraries(opentrack proc) +endif() + # ---- # make install diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp index a00cbb17..f3388c4f 100755 --- a/opentrack-compat/process-list.hpp +++ b/opentrack-compat/process-list.hpp @@ -36,10 +36,12 @@ static QStringList get_all_executable_names() #elif defined __APPLE__ #include #include +#include +#include #include +#include #include -// link to libproc template static QStringList get_all_executable_names() { @@ -51,21 +53,69 @@ static QStringList get_all_executable_names() int numproc = proc_listpids(PROC_ALL_PIDS, 0, nullptr, 0); if (numproc == -1) { - qDebug() << "numproc failed" << errno; - break; + qDebug() << "proc_listpids numproc failed" << errno; + return ret; } vec.resize(numproc); int cnt = proc_listpids(PROC_ALL_PIDS, 0, &vec[0], sizeof(int) * numproc); + if (cnt <= numproc) { - char name[2 * 2 * MAXCOMLEN + 1]; - for (int i = 0; i < cnt; i++) + std::vector arglist; + int mib[2] { CTL_KERN, KERN_ARGMAX }; + size_t sz = sizeof(int); + int maxarg = 0; + if (sysctl(mib, 2, &maxarg, &sz, NULL, 0) == -1) + { + qDebug() << "sysctl KERN_ARGMAX" << errno; + return ret; + } + arglist.resize(maxarg); + for (int i = 0; i < numproc; i++) { - int ret = proc_name(vec[i], name, sizeof(name)-1); - if (ret <= 0) + size_t maxarg_ = (size_t)maxarg; + int mib[3] { CTL_KERN, KERN_PROCARGS2, vec[i] }; + if (sysctl(mib, 3, &arglist[0], &maxarg_, NULL, 0) == -1) + { + //qDebug() << "sysctl KERN_PROCARGS2" << vec[i] << errno; continue; - name[ret] = '\0'; - ret.append(name); + } + QStringList cmdline; + for (unsigned j = sizeof(int) + strlen(&arglist[sizeof(int)]); j < maxarg_; j++) + { + QString arg(&arglist[j]); + if (arg.size() != 0) + { + cmdline << arg; + j += arg.size(); + } + } + if (cmdline.size() > 0) + { + int idx = cmdline[0].lastIndexOf('/'); + if (idx != -1) + { + QString tmp = cmdline[0].mid(idx+1); + if (cmdline.size() > 1 && (tmp == "wine.bin" || tmp == "wine")) + { + idx = cmdline[1].lastIndexOf('/'); + if (idx == -1) + idx = cmdline[1].lastIndexOf('\\'); + if (idx != -1) + { + ret.append(cmdline[1].mid(idx+1)); + } + else + ret.append(cmdline[1]); + } + else + { + ret.append(tmp); + } + } + else + ret.append(cmdline[0]); + } } return ret; } -- cgit v1.2.3 From 1ebfd95dce50db4fa9523a26aba1f80e4ff5db52 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 14 Aug 2015 09:28:42 +0200 Subject: fix Linux game detection code Issue: #181 --- CMakeLists.txt | 15 ++++++++++----- opentrack-compat/process-list.hpp | 10 ++++++---- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'opentrack-compat') diff --git a/CMakeLists.txt b/CMakeLists.txt index 18e2a9cd..54fbfed5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,7 +144,11 @@ IF(WIN32) SET(SDK_CONSOLE_DEBUG FALSE CACHE BOOL "Console window visible at runtime") ENDIF() -IF("${CMAKE_SYSTEM}" MATCHES "Linux" OR APPLE) +IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(LINUX TRUE) +endif() + +if(LINUX OR APPLE) set(SDK_XPLANE "" CACHE PATH "Path to X-Plane SDK") set(SDK_ENABLE_LIBEVDEV FALSE CACHE BOOL "libevdev virtual joystick protocol support") endif() @@ -505,15 +509,16 @@ endif() link_with_dinput8(opentrack) target_link_libraries(opentrack ${MY_QT_LIBS}) -if(CMAKE_SYSTEM STREQUAL LINUX) - link_libraries(rt) -endif() - if(APPLE) # for process detector target_link_libraries(opentrack proc) endif() +if(LINUX) + # for process detector + target_link_libraries(opentrack procps) +endif() + # ---- # make install diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp index f3388c4f..6b139739 100755 --- a/opentrack-compat/process-list.hpp +++ b/opentrack-compat/process-list.hpp @@ -124,7 +124,6 @@ static QStringList get_all_executable_names() #elif defined __linux -// link to procps #include #include template @@ -139,10 +138,13 @@ static QStringList get_all_executable_names() } for (int i = 0; procs[i]; i++) { - auto& proc = *procs[i]; - ret.append(proc.cmd); + // note, wine sets argv[0] so no parsing like in OSX case + auto proc = procs[i]; + if (proc->cmdline && proc->cmdline[0]) + ret.append(proc->cmdline[0]); + freeproc(procs[i]); } - freeproctab(procs); + free(procs); return ret; } -- cgit v1.2.3 From e419da059974933deec16a597f5888ade27d8617 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 14 Aug 2015 09:54:12 +0200 Subject: run basename on Linux process detector --- opentrack-compat/process-list.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'opentrack-compat') diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp index 6b139739..7dd206ab 100755 --- a/opentrack-compat/process-list.hpp +++ b/opentrack-compat/process-list.hpp @@ -141,7 +141,12 @@ static QStringList get_all_executable_names() // note, wine sets argv[0] so no parsing like in OSX case auto proc = procs[i]; if (proc->cmdline && proc->cmdline[0]) - ret.append(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); -- cgit v1.2.3 From 0d4899cc4ad3c77c09fa97dbab99d3e975b0cab3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 14 Aug 2015 09:55:42 +0200 Subject: reformat --- opentrack-compat/process-list.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'opentrack-compat') diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp index 7dd206ab..65735740 100755 --- a/opentrack-compat/process-list.hpp +++ b/opentrack-compat/process-list.hpp @@ -141,12 +141,12 @@ static QStringList get_all_executable_names() // 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); + { + 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); -- cgit v1.2.3 From 21cd2c012ef23ec3f4b374d82056f1fa1694d904 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 22 Aug 2015 19:02:57 +0200 Subject: props changed only Some source files had executable bit on. Remove it. --- CMakeLists.txt | 0 bin/NPClient.dll | Bin bin/NPClient64.dll | Bin bin/freetrackclient.dll | Bin clientfiles/make-csv.pl | 0 csv/csv.cpp | 0 facetracknoir/keyboard.h | 0 facetracknoir/process_detector.cpp | 0 facetracknoir/process_detector.h | 0 ftnoir_filter_kalman/ftnoir_filter_kalman.h | 0 ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp | 0 ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp | 0 ftnoir_tracker_aruco/include/markerdetector.h | 0 ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 0 ftnoir_tracker_udp/ftnoir_tracker_udp.cpp | 0 opentrack-compat/process-list.hpp | 0 opentrack/simple-mat.hpp | 0 opentrack/tracker.cpp | 0 opentrack/win32-shortcuts.cpp | 0 opentrack/win32-shortcuts.h | 0 pose-widget/glwidget.cpp | 0 pose-widget/glwidget.h | 0 qfunctionconfigurator/functionconfig.cpp | 0 23 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 CMakeLists.txt mode change 100755 => 100644 bin/NPClient.dll mode change 100755 => 100644 bin/NPClient64.dll mode change 100755 => 100644 bin/freetrackclient.dll mode change 100755 => 100644 clientfiles/make-csv.pl mode change 100755 => 100644 csv/csv.cpp mode change 100755 => 100644 facetracknoir/keyboard.h mode change 100755 => 100644 facetracknoir/process_detector.cpp mode change 100755 => 100644 facetracknoir/process_detector.h mode change 100755 => 100644 ftnoir_filter_kalman/ftnoir_filter_kalman.h mode change 100755 => 100644 ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp mode change 100755 => 100644 ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp mode change 100755 => 100644 ftnoir_tracker_aruco/include/markerdetector.h mode change 100755 => 100644 ftnoir_tracker_pt/ftnoir_tracker_pt.cpp mode change 100755 => 100644 ftnoir_tracker_udp/ftnoir_tracker_udp.cpp mode change 100755 => 100644 opentrack-compat/process-list.hpp mode change 100755 => 100644 opentrack/simple-mat.hpp mode change 100755 => 100644 opentrack/tracker.cpp mode change 100755 => 100644 opentrack/win32-shortcuts.cpp mode change 100755 => 100644 opentrack/win32-shortcuts.h mode change 100755 => 100644 pose-widget/glwidget.cpp mode change 100755 => 100644 pose-widget/glwidget.h mode change 100755 => 100644 qfunctionconfigurator/functionconfig.cpp (limited to 'opentrack-compat') diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 diff --git a/bin/NPClient.dll b/bin/NPClient.dll old mode 100755 new mode 100644 diff --git a/bin/NPClient64.dll b/bin/NPClient64.dll old mode 100755 new mode 100644 diff --git a/bin/freetrackclient.dll b/bin/freetrackclient.dll old mode 100755 new mode 100644 diff --git a/clientfiles/make-csv.pl b/clientfiles/make-csv.pl old mode 100755 new mode 100644 diff --git a/csv/csv.cpp b/csv/csv.cpp old mode 100755 new mode 100644 diff --git a/facetracknoir/keyboard.h b/facetracknoir/keyboard.h old mode 100755 new mode 100644 diff --git a/facetracknoir/process_detector.cpp b/facetracknoir/process_detector.cpp old mode 100755 new mode 100644 diff --git a/facetracknoir/process_detector.h b/facetracknoir/process_detector.h old mode 100755 new mode 100644 diff --git a/ftnoir_filter_kalman/ftnoir_filter_kalman.h b/ftnoir_filter_kalman/ftnoir_filter_kalman.h old mode 100755 new mode 100644 diff --git a/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp b/ftnoir_protocol_fsuipc/ftnoir_protocol_fsuipc.cpp old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp b/ftnoir_tracker_aruco/ftnoir_tracker_aruco.cpp old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_aruco/include/markerdetector.h b/ftnoir_tracker_aruco/include/markerdetector.h old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp old mode 100755 new mode 100644 diff --git a/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp b/ftnoir_tracker_udp/ftnoir_tracker_udp.cpp old mode 100755 new mode 100644 diff --git a/opentrack-compat/process-list.hpp b/opentrack-compat/process-list.hpp old mode 100755 new mode 100644 diff --git a/opentrack/simple-mat.hpp b/opentrack/simple-mat.hpp old mode 100755 new mode 100644 diff --git a/opentrack/tracker.cpp b/opentrack/tracker.cpp old mode 100755 new mode 100644 diff --git a/opentrack/win32-shortcuts.cpp b/opentrack/win32-shortcuts.cpp old mode 100755 new mode 100644 diff --git a/opentrack/win32-shortcuts.h b/opentrack/win32-shortcuts.h old mode 100755 new mode 100644 diff --git a/pose-widget/glwidget.cpp b/pose-widget/glwidget.cpp old mode 100755 new mode 100644 diff --git a/pose-widget/glwidget.h b/pose-widget/glwidget.h old mode 100755 new mode 100644 diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp old mode 100755 new mode 100644 -- cgit v1.2.3