From b45b5700c6be73c3da030a943cc69997f209b887 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 26 Sep 2023 09:52:05 +0200
Subject: [PATCH] udev: raise RLIMIT_NOFILE as high as we can

We might need a lot of fds on large systems, hence raise RLIMIT_NOFILE
to what the service manager allows us, which is quite a lot these days.

udev already sets FORK_RLIMIT_NOFILE_SAFE when forking of chilren, thus
ensuring that forked off processes get their RLIMIT_NOFILE soft limit
reset to 1K for compat with crappy old select().

Replaces: #29298
Fixes: #28583
(cherry picked from commit 1617424ce76d797d081dd6cb1082b954c4d2bf38)
(cherry picked from commit c98a24bdbdb830a5081d5ec972d62d08547d7255)
(cherry picked from commit b60cf1f7f489e25c730e21c4c17f968330846325)

Conflict:code context adaptation
Reference:https://github.com/systemd/systemd-stable/commit/b45b5700c6be73c3da030a943cc69997f209b887
---
 src/udev/udevd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index c83c59516b..2095062b93 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -55,6 +55,7 @@
 #include "pretty-print.h"
 #include "proc-cmdline.h"
 #include "process-util.h"
+#include "rlimit-util.h"
 #include "selinux-util.h"
 #include "signal-util.h"
 #include "socket-util.h"
@@ -2040,6 +2041,9 @@ int run_udevd(int argc, char *argv[]) {
         if (r < 0)
                 return r;
 
+        /* Make sure we can have plenty fds (for example for pidfds) */
+        (void) rlimit_nofile_bump(-1);
+
         r = mkdir_errno_wrapper("/run/udev", 0755);
         if (r < 0 && r != -EEXIST)
                 return log_error_errno(r, "Failed to create /run/udev: %m");
-- 
2.33.0

