]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: fd: move raise_rlim_nofile to limits
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 10 Jul 2024 10:33:39 +0000 (12:33 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 10 Jul 2024 16:05:48 +0000 (18:05 +0200)
Let's move raise_rlim_nofile() from 'fd' compilation unit to 'limits', as it
wraps setrlimit to change process RLIMIT_NOFILE.

include/haproxy/fd.h
include/haproxy/limits.h
src/fd.c
src/limits.c

index 11212ffcdfe7650f3f8a5ea84bc1bfe295e44fe7..7b8e8997b20ea55372176b25530aee5ddb6a7371 100644 (file)
@@ -82,7 +82,6 @@ ssize_t fd_write_frag_line(int fd, size_t maxlen, const struct ist pfx[], size_t
 void my_closefrom(int start);
 
 struct rlimit;
-int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit);
 
 int compute_poll_timeout(int next);
 void fd_leaving_poll(int wait_time, int status);
index 2a76e2c95d19f601ba34a62a74926a4b723e6fbb..4db6989b33f9c18cc8039239ae1fa94a54647504 100644 (file)
@@ -9,4 +9,9 @@
 #define _HAPROXY_LIMITS_H
 #include <sys/resource.h>
 
+/* handlers to manipulate system resources limits granted by OS to process and
+ * to tie them up with the internal process limits
+ */
+int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit);
+
 #endif /* _HAPROXY_LIMITS_H */
index 9b625157e58ee3b2cc6c5248a97028149d8bfbb6..2dd265527002768ef44c48e4d4f47acf7ced36cf 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -1019,32 +1019,6 @@ void my_closefrom(int start)
 }
 #endif // defined(USE_POLL)
 
-/* Sets the RLIMIT_NOFILE setting to <new_limit> and returns the previous one
- * in <old_limit> if the pointer is not NULL, even if set_rlimit() fails. The
- * two pointers may point to the same variable as the copy happens after
- * setting the new value. The value is only changed if at least one of the new
- * limits is strictly higher than the current one, otherwise returns 0 without
- * changing anything. The getrlimit() or setrlimit() syscall return value is
- * returned and errno is preserved.
- */
-int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit)
-{
-       struct rlimit limit = { };
-       int ret = 0;
-
-       ret = getrlimit(RLIMIT_NOFILE, &limit);
-
-       if (ret == 0 &&
-           (limit.rlim_max < new_limit->rlim_max ||
-            limit.rlim_cur < new_limit->rlim_cur)) {
-               ret = setrlimit(RLIMIT_NOFILE, new_limit);
-       }
-
-       if (old_limit)
-               *old_limit = limit;
-
-       return ret;
-}
 
 /* Computes the bounded poll() timeout based on the next expiration timer <next>
  * by bounding it to MAX_DELAY_MS. <next> may equal TICK_ETERNITY. The pollers
index a80a2ac217d69ec6770fee4f322df14109abe953..8d0bf7b4639b811511ec96eebb02bb3d63b7eba6 100644 (file)
 #include <haproxy/proxy.h>
 
 
+/* Sets the RLIMIT_NOFILE setting to <new_limit> and returns the previous one
+ * in <old_limit> if the pointer is not NULL, even if set_rlimit() fails. The
+ * two pointers may point to the same variable as the copy happens after
+ * setting the new value. The value is only changed if at least one of the new
+ * limits is strictly higher than the current one, otherwise returns 0 without
+ * changing anything. The getrlimit() or setrlimit() syscall return value is
+ * returned and errno is preserved.
+ */
+int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit)
+{
+       struct rlimit limit = { };
+       int ret = 0;
+
+       ret = getrlimit(RLIMIT_NOFILE, &limit);
+
+       if (ret == 0 &&
+           (limit.rlim_max < new_limit->rlim_max ||
+            limit.rlim_cur < new_limit->rlim_cur)) {
+               ret = setrlimit(RLIMIT_NOFILE, new_limit);
+       }
+
+       if (old_limit)
+               *old_limit = limit;
+
+       return ret;
+}