tags 1024225 patch thankyou Attached is a patch for veyon to work with libproc2. I cannot test it because I can't actually get veyon to build as the upstream is in a different branch and remote. It looks ok but might need some additional work.
- Craig
diff --git a/plugins/platform/linux/CMakeLists.txt b/plugins/platform/linux/CMakeLists.txt index 213dee746..1f6d77084 100644 --- a/plugins/platform/linux/CMakeLists.txt +++ b/plugins/platform/linux/CMakeLists.txt @@ -2,7 +2,18 @@ add_subdirectory(auth-helper) find_package(X11 REQUIRED) find_package(PkgConfig QUIET) -pkg_check_modules(procps REQUIRED libprocps) +pkg_check_modules(procps libproc2) +if(procps_FOUND) + add_definitions(-DHAVE_LIBPROC2) +else() + pkg_check_modules(procps libprocps) + if(procps_FOUND) + add_definitions(-DHAVE_LIBPROCPS) + else() + message( FATAL_ERROR "libproc2/libprocps not found") + endif() +endif() + pkg_check_modules(fakekey libfakekey) include(BuildVeyonPlugin) diff --git a/plugins/platform/linux/LinuxCoreFunctions.cpp b/plugins/platform/linux/LinuxCoreFunctions.cpp index ed8f0d6a7..95661ab93 100644 --- a/plugins/platform/linux/LinuxCoreFunctions.cpp +++ b/plugins/platform/linux/LinuxCoreFunctions.cpp @@ -33,7 +33,12 @@ #include <unistd.h> #include <grp.h> +#ifdef HAVE_LIBPROCPS #include <proc/readproc.h> +#endif +#ifdef HAVE_LIBPROC2 +#include <libproc2/pids.h> +#endif #include "LinuxCoreFunctions.h" #include "LinuxDesktopIntegration.h" @@ -443,7 +448,7 @@ void LinuxCoreFunctions::restartDisplayManagers() } - +#ifdef HAVE_LIBPROCPS void LinuxCoreFunctions::forEachChildProcess( const std::function<bool(proc_t*)>& visitor, int parentPid, int flags, bool visitParent ) { @@ -473,7 +478,46 @@ void LinuxCoreFunctions::forEachChildProcess( const std::function<bool(proc_t*)> closeproc( proc ); } +#elif defined(HAVE_LIBPROC2) +/* + * items lists the items you want to fetch, the first two must be PID and PPID + */ +void LinuxCoreFunctions::forEachChildProcess( const std::function<bool(struct pids_stack*,struct pids_info*)>& visitor, + int parentPid, enum pids_item *items, bool visitParent ) +{ + QProcessEnvironment sessionEnv; + + struct pids_info *info = NULL; + struct pids_stack *stack; + QList<int> ppids; + + if (items[0] != PIDS_ID_PID || items[1] != PIDS_ID_PPID) + return; + + + if ( procps_pids_new(&info, Items, sizeof(*items)) < 0) + return; + + while( (stack = procps_pids_get(info, PIDS_FETCH_TASKS_ONLY))) + { + int ppid = PIDS_VAL(1, s_int, stack, info); + + if( ppid == parentPid ) + { + if( visitParent == false || visitor( stack, info ) ) + { + ppids.append( PIDS_VAL(0, s_int, stack, info)); + } + } + else if( ppids.contains( ppid ) && visitor( stack, info ) ) + { + ppids.append( PIDS_VAL(0, s_int, stack, info)); + } + } + procps_pids_unref(&info); +} +#endif bool LinuxCoreFunctions::waitForProcess( qint64 pid, int timeout, int sleepInterval ) diff --git a/plugins/platform/linux/LinuxServerProcess.cpp b/plugins/platform/linux/LinuxServerProcess.cpp index a7506e762..e8d668e9b 100644 --- a/plugins/platform/linux/LinuxServerProcess.cpp +++ b/plugins/platform/linux/LinuxServerProcess.cpp @@ -86,6 +86,7 @@ void LinuxServerProcess::stop() const auto sendSignalRecursively = []( pid_t pid, int sig ) { if( pid > 0 ) { +#ifdef HAVE_LIBPROCPS LinuxCoreFunctions::forEachChildProcess( [=]( proc_t* procInfo ) { if( procInfo->tid > 0 && ::kill( procInfo->tid, sig ) < 0 && errno != ESRCH ) @@ -95,6 +96,19 @@ void LinuxServerProcess::stop() return true; }, pid, 0, true ); +#elif defined(HAVE_LIBPROC2) + LinuxCoreFunctions::forEachChildProcess( + [=]( struct pids_stack *stack, struct pids_info *info ) { + pid_t tid = PIDS_VAL(0, s_int, stack, info); + if( tid > 0 && ::kill( tid, sig ) < 0 && errno != ESRCH ) + { + vCritical() << "kill() failed with" << errno; + } + return true; + }, + pid, + {PIDS_ID_PID, PIDS_ID_PPID}, true ); +#endif /* HAVE_LIBPROC2 */ if( ::kill( pid, sig ) < 0 && errno != ESRCH ) { diff --git a/plugins/platform/linux/LinuxSessionFunctions.cpp b/plugins/platform/linux/LinuxSessionFunctions.cpp index ad51a0847..b99b31aa8 100644 --- a/plugins/platform/linux/LinuxSessionFunctions.cpp +++ b/plugins/platform/linux/LinuxSessionFunctions.cpp @@ -26,7 +26,11 @@ #include <QDBusReply> #include <QProcessEnvironment> +#ifdef HAVE_LIBPROCPS #include <proc/readproc.h> +#elif defined(HAVE_LIBPROC2) +#include <libproc2/pids.h> +#endif #include "LinuxCoreFunctions.h" #include "LinuxSessionFunctions.h" @@ -293,7 +297,7 @@ LinuxSessionFunctions::LoginDBusSessionSeat LinuxSessionFunctions::getSessionSea QProcessEnvironment LinuxSessionFunctions::getSessionEnvironment( int sessionLeaderPid ) { QProcessEnvironment sessionEnv; - +#ifdef HAVE_LIBPROCPS LinuxCoreFunctions::forEachChildProcess( [&sessionEnv]( proc_t* procInfo ) { if( procInfo->environ != nullptr ) @@ -314,6 +318,32 @@ QProcessEnvironment LinuxSessionFunctions::getSessionEnvironment( int sessionLea return false; }, sessionLeaderPid, PROC_FILLENV, true ); +#elif defined(HAVE_LIBPROC2) + LinuxCoreFunctions::forEachChildProcess( + [&sessionEnv]( struct pids_stack *stack, struct pids_info *info ) { + char *environ = PIDS_VAL(2, str, stack, info); + + if( environ != nullptr ) + { + for( int i = 0; environ[i]; ++i ) + { + const auto env = QString::fromUtf8( environ[i] ); + const auto separatorPos = env.indexOf( QLatin1Char('=') ); + if( separatorPos > 0 ) + { + sessionEnv.insert( env.left( separatorPos ), env.mid( separatorPos+1 ) ); + } + } + + return true; + } + + return false; + }, + sessionLeaderPid, + {PIDS_ID_PID, PIDS_ID_PPID, PIDS_ENVIRON}, + true ); +#endif return sessionEnv; }