File: fix_cifs_file_locks.patch

package info (click to toggle)
kio 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 41,496 kB
  • sloc: cpp: 123,468; xml: 528; ansic: 466; ruby: 60; sh: 21; makefile: 10
file content (45 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From d1a2dab1da43d613ae5a8459ddcb62c8d78c46ff Mon Sep 17 00:00:00 2001
From: Kevin Ottens <kevin.ottens@enioka.com>
Date: Fri, 5 Jan 2024 11:51:49 +0100
Subject: [PATCH] Don't leak file descriptors when spawning new workers

By default we inherit file descriptors from the parent in
the worker process. This is a leak of resources since the
worker won't be able to do anything with them. Also, in
the case of CIFS this causes locks which might lead to bad
surprises in the parent process.
---

Index: kio-5.103.0/src/kioslave/kioslave.cpp
===================================================================
--- kio-5.103.0.orig/src/kioslave/kioslave.cpp
+++ kio-5.103.0/src/kioslave/kioslave.cpp
@@ -18,6 +18,10 @@
 #include <QPluginLoader>
 #include <QString>
 
+#ifdef Q_OS_UNIX
+#include <sys/resource.h>
+#endif
+
 #ifdef Q_OS_WIN
 #include <QProcess>
 #include <QStandardPaths>
@@ -40,6 +44,17 @@ extern "C" KIO::AuthInfo *_kioslave_init
 
 int main(int argc, char **argv)
 {
+#ifdef Q_OS_UNIX
+    int max_fd = INT_MAX;
+    struct rlimit limit;
+    if (getrlimit(RLIMIT_NOFILE, &limit) == 0) {
+        max_fd = limit.rlim_cur;
+    }
+    for (int fd = STDERR_FILENO + 1; fd < max_fd; fd++) {
+        ::close(fd);
+    }
+#endif
+
     if (argc < 5) {
         fprintf(stderr, "Usage: kioslave5 <slave-lib> <protocol> <klauncher-socket> <app-socket>\n\nThis program is part of KDE.\n");
         return 1;