x11-misc/barrier: Patch around USE=-gui and infinite loop issues
authorJames Le Cuirot <chewi@gentoo.org>
Wed, 11 Mar 2020 23:19:18 +0000 (23:19 +0000)
committerJames Le Cuirot <chewi@gentoo.org>
Wed, 11 Mar 2020 23:20:31 +0000 (23:20 +0000)
These patches are already merged upstream.

Closes: https://bugs.gentoo.org/712140
Package-Manager: Portage-2.3.93, Repoman-2.3.20
Signed-off-by: James Le Cuirot <chewi@gentoo.org>
x11-misc/barrier/barrier-2.3.2-r1.ebuild [moved from x11-misc/barrier/barrier-2.3.2.ebuild with 95% similarity]
x11-misc/barrier/files/barrier-2.3.2-inf-loop.patch [new file with mode: 0644]
x11-misc/barrier/files/barrier-2.3.2-no-avahi.patch [new file with mode: 0644]

similarity index 95%
rename from x11-misc/barrier/barrier-2.3.2.ebuild
rename to x11-misc/barrier/barrier-2.3.2-r1.ebuild
index e55957982652e2b1909582cff6b6f86b138fc740..4b553a9888e2e5d2eecd7169dbdc9c33036e3f84 100644 (file)
@@ -40,6 +40,8 @@ DEPEND="
 "
 
 PATCHES=(
+       "${FILESDIR}"/${P}-inf-loop.patch
+       "${FILESDIR}"/${P}-no-avahi.patch
        "${FILESDIR}"/${P}-pthread.patch
 )
 
diff --git a/x11-misc/barrier/files/barrier-2.3.2-inf-loop.patch b/x11-misc/barrier/files/barrier-2.3.2-inf-loop.patch
new file mode 100644 (file)
index 0000000..125b903
--- /dev/null
@@ -0,0 +1,132 @@
+From c79120c049d825fedeed70d5a1a9dc64d17ce9f0 Mon Sep 17 00:00:00 2001
+From: Vasily Galkin <galkin-vv@ya.ru>
+Date: Sun, 9 Feb 2020 23:27:26 +0300
+Subject: [PATCH] Fix infinite loop on fast TCP disconnection
+
+The commit a841b28 changed the condition for removing job from processing.
+New flag MultiplexerJobStatus::continue_servicing become used
+instead of checking pointer for NULL.
+However for cases when TCPSocket::newJob() returns nullptr
+the behaviour changed: earlier the job was removed, but after change
+it is called again, since MultiplexerJobStatus equal to {true, nullptr}
+means "run this job again".
+
+This leads to problem with eating CPU and RAM on linux
+https://github.com/debauchee/barrier/issues/470
+
+There is similar windows problem, but not sure it is related.
+https://github.com/debauchee/barrier/issues/552
+
+Since it looks that the goal of a841b28 was only clarifying
+object ownership and not changing job deletion behaviour,
+this commit tries to get original behaviour and fix the bugs above
+by returning {false, nullptr} instead of {true, nullptr}
+when TCPSocket::newJob() returns nullptr.
+---
+ src/lib/net/SecureSocket.cpp |  4 ++--
+ src/lib/net/TCPSocket.cpp    | 25 +++++++++++++------------
+ src/lib/net/TCPSocket.h      |  3 ++-
+ 3 files changed, 17 insertions(+), 15 deletions(-)
+
+diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp
+index 99f626e8..92abea3c 100644
+--- a/src/lib/net/SecureSocket.cpp
++++ b/src/lib/net/SecureSocket.cpp
+@@ -761,7 +761,7 @@ MultiplexerJobStatus SecureSocket::serviceConnect(ISocketMultiplexerJob* job,
+     // If status > 0, success
+     if (status > 0) {
+         sendEvent(m_events->forIDataSocket().secureConnected());
+-        return {true, newJob()};
++        return newJobOrStopServicing();
+     }
+     // Retry case
+@@ -793,7 +793,7 @@ MultiplexerJobStatus SecureSocket::serviceAccept(ISocketMultiplexerJob* job,
+     // If status > 0, success
+     if (status > 0) {
+         sendEvent(m_events->forClientListener().accepted());
+-        return {true, newJob()};
++        return newJobOrStopServicing();
+     }
+     // Retry case
+diff --git a/src/lib/net/TCPSocket.cpp b/src/lib/net/TCPSocket.cpp
+index 4f4251ad..09a8f17e 100644
+--- a/src/lib/net/TCPSocket.cpp
++++ b/src/lib/net/TCPSocket.cpp
+@@ -403,6 +403,15 @@ void TCPSocket::setJob(std::unique_ptr<ISocketMultiplexerJob>&& job)
+     }
+ }
++MultiplexerJobStatus TCPSocket::newJobOrStopServicing()
++{
++    auto new_job = newJob();
++    if (new_job)
++        return {true, std::move(new_job)};
++    else
++        return {false, {}};
++}
++
+ std::unique_ptr<ISocketMultiplexerJob> TCPSocket::newJob()
+ {
+     // note -- must have m_mutex locked on entry
+@@ -519,22 +528,14 @@ MultiplexerJobStatus TCPSocket::serviceConnecting(ISocketMultiplexerJob* job, bo
+         catch (XArchNetwork& e) {
+             sendConnectionFailedEvent(e.what());
+             onDisconnected();
+-            auto new_job = newJob();
+-            if (new_job)
+-                return {true, std::move(new_job)};
+-            else
+-                return {false, {}};
++            return newJobOrStopServicing();
+         }
+     }
+     if (write) {
+         sendEvent(m_events->forIDataSocket().connected());
+         onConnected();
+-        auto new_job = newJob();
+-        if (new_job)
+-            return {true, std::move(new_job)};
+-        else
+-            return {false, {}};
++        return newJobOrStopServicing();
+     }
+     return {true, {}};
+@@ -548,7 +549,7 @@ MultiplexerJobStatus TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
+     if (error) {
+         sendEvent(m_events->forISocket().disconnected());
+         onDisconnected();
+-        return {true, newJob()};
++        return newJobOrStopServicing();
+     }
+     EJobResult writeResult = kRetry;
+@@ -603,7 +604,7 @@ MultiplexerJobStatus TCPSocket::serviceConnected(ISocketMultiplexerJob* job,
+     if (writeResult == kBreak || readResult == kBreak) {
+         return {false, {}};
+     } else if (writeResult == kNew || readResult == kNew) {
+-        return {true, newJob()};
++        return newJobOrStopServicing();
+     } else {
+         return {true, {}};
+     }
+diff --git a/src/lib/net/TCPSocket.h b/src/lib/net/TCPSocket.h
+index 28891353..0b988886 100644
+--- a/src/lib/net/TCPSocket.h
++++ b/src/lib/net/TCPSocket.h
+@@ -76,7 +76,8 @@ protected:
+     void removeJob();
+     void setJob(std::unique_ptr<ISocketMultiplexerJob>&& job);
+-    
++    MultiplexerJobStatus newJobOrStopServicing();
++
+     bool                isReadable() { return m_readable; }
+     bool                isWritable() { return m_writable; }
+-- 
+2.24.1
+
diff --git a/x11-misc/barrier/files/barrier-2.3.2-no-avahi.patch b/x11-misc/barrier/files/barrier-2.3.2-no-avahi.patch
new file mode 100644 (file)
index 0000000..481a23a
--- /dev/null
@@ -0,0 +1,25 @@
+From 93a4035409ed5a4349c9848c3dae3ec670884ee0 Mon Sep 17 00:00:00 2001
+From: Tetja Rediske <tetja+gitlab@tetja.de~>
+Date: Sat, 19 Oct 2019 00:28:13 +0200
+Subject: [PATCH] make non-gui variants build without avahi
+
+---
+ CMakeLists.txt | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 7f9efac8..8e10776e 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -175,7 +175,7 @@ if (UNIX)
+             link_directories("/usr/X11R6/lib")
+         endif()
+-        if (${PKG_CONFIG_FOUND})
++        if (BARRIER_BUILD_GUI AND ${PKG_CONFIG_FOUND})
+             pkg_check_modules (AVAHI_COMPAT REQUIRED avahi-compat-libdns_sd)
+             include_directories (BEFORE SYSTEM ${AVAHI_COMPAT_INCLUDE_DIRS})
+             set (CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${AVAHI_COMPAT_INCLUDE_DIRS}")
+-- 
+2.24.1
+