From a37ac71c33275b007dcb80531f900e3d930930f3 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Thu, 22 Dec 2016 14:30:57 +0100 Subject: [PATCH] Client: Don't crash when the receiver of a paste closes the pipe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignore the SIGPIPE signal Task-number: QTBUG-57202 Change-Id: If22381f446675836aeb741a8e6da5473b0a27301 Reviewed-by: Martin Gräßlin Reviewed-by: Paul Olav Tvete --- src/plugins/platforms/wayland/qwaylanddatasource.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/platforms/wayland/qwaylanddatasource.cpp b/src/plugins/platforms/wayland/qwaylanddatasource.cpp index 036bd0d8651..c61de181ba6 100644 --- a/src/plugins/platforms/wayland/qwaylanddatasource.cpp +++ b/src/plugins/platforms/wayland/qwaylanddatasource.cpp @@ -48,6 +48,7 @@ #include #include +#include #if QT_CONFIG(draganddrop) @@ -85,7 +86,16 @@ void QWaylandDataSource::data_source_send(const QString &mime_type, int32_t fd) { QByteArray content = QWaylandMimeHelper::getByteArray(m_mime_data, mime_type); if (!content.isEmpty()) { + // Create a sigpipe handler that does nothing, or clients may be forced to terminate + // if the pipe is closed in the other end. + struct sigaction action, oldAction; + action.sa_handler = SIG_IGN; + sigemptyset (&action.sa_mask); + action.sa_flags = 0; + + sigaction(SIGPIPE, &action, &oldAction); write(fd, content.constData(), content.size()); + sigaction(SIGPIPE, &oldAction, nullptr); } close(fd); }