]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: export get_max_fd() so that we can use it in tests
authorLennart Poettering <lennart@poettering.net>
Thu, 12 Aug 2021 08:46:10 +0000 (10:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 27 Oct 2021 15:56:36 +0000 (17:56 +0200)
src/basic/fd-util.c
src/basic/fd-util.h
src/test/test-fd-util.c

index 50666e6375c9d23fb0bd8ad5ac43848e1cee59c3..63c37fec4d8257e8abb62ad4a10137edb0323145 100644 (file)
@@ -187,7 +187,7 @@ _pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) {
         return false;
 }
 
-static int get_max_fd(void) {
+int get_max_fd(void) {
         struct rlimit rl;
         rlim_t m;
 
index e929386b539218f0ed5ca14899d2ff2a94245b08..dd5207bd88a8c84fd851fae5c96c0543b81b023a 100644 (file)
@@ -57,6 +57,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL);
 int fd_nonblock(int fd, bool nonblock);
 int fd_cloexec(int fd, bool cloexec);
 
+int get_max_fd(void);
+
 int close_all_fds(const int except[], size_t n_except);
 int close_all_fds_without_malloc(const int except[], size_t n_except);
 
index 4c51592c263fe2da884dcf9798b397cf92b785a0..6001f8e057a9391d491b478fc0bce742754097b1 100644 (file)
@@ -215,18 +215,18 @@ static size_t validate_fds(
 
 static void test_close_all_fds(void) {
         _cleanup_free_ int *fds = NULL, *keep = NULL;
-        struct rlimit rl;
         size_t n_fds, n_keep;
+        int max_fd;
 
         log_info("/* %s */", __func__);
 
         rlimit_nofile_bump(-1);
 
-        assert_se(getrlimit(RLIMIT_NOFILE, &rl) >= 0);
-        assert_se(rl.rlim_cur > 10);
+        max_fd = get_max_fd();
+        assert_se(max_fd > 10);
 
         /* Try to use 5000 fds, but when we can't bump the rlimit to make that happen use the whole limit minus 10 */
-        n_fds = MIN((rl.rlim_cur & ~1U) - 10U, 5000U);
+        n_fds = MIN(((size_t) max_fd & ~1U) - 10U, 5000U);
         assert_se((n_fds & 1U) == 0U); /* make sure even number of fds */
 
         /* Allocate the determined number of fds, always two at a time */