From 96af5965eeeff089b1116c8ac8da6b9bd4f2a4b5 Mon Sep 17 00:00:00 2001 From: Fabian Vogt Date: Sat, 18 Nov 2017 23:25:06 +0100 Subject: [PATCH] Fix leaking of FDs requested from logind Summary: The takeDevice method calls dup, but that syscall removes the O_CLOEXEC flag as a side-effect. This resulted in all child processes of kwin_wayland having an open file descriptor for those devices. Test Plan: Looked at the open FDs of the startplasma script. Before, all /dev/input/eventX files and /dev/dri/card0 were open. Now, none of those are part of /proc/PID/fd/ Reviewers: #plasma, graesslin Reviewed By: #plasma, graesslin Subscribers: kwin, plasma-devel, #kwin Tags: #plasma Differential Revision: https://phabricator.kde.org/D8887 --- logind.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/logind.cpp b/logind.cpp index 4a86d77e03..c300cac675 100644 --- a/logind.cpp +++ b/logind.cpp @@ -36,6 +36,7 @@ along with this program. If not, see . #ifndef major #include #endif +#include #include #include "utils.h" @@ -378,7 +379,9 @@ int LogindIntegration::takeDevice(const char *path) qCDebug(KWIN_CORE) << "Could not take device" << path << ", cause: " << reply.errorMessage(); return -1; } - return dup(reply.arguments().first().value().fileDescriptor()); + + // The dup syscall removes the CLOEXEC flag as a side-effect. So use fcntl's F_DUPFD_CLOEXEC cmd. + return fcntl(reply.arguments().first().value().fileDescriptor(), F_DUPFD_CLOEXEC, 0); } void LogindIntegration::releaseDevice(int fd)