mirror of
https://github.com/systemd/systemd.git
synced 2024-10-31 07:51:21 +03:00
fd-util: export get_max_fd() so that we can use it in tests
This commit is contained in:
parent
ab27b2fe56
commit
73fc0cbc87
@ -187,7 +187,7 @@ _pure_ static bool fd_in_set(int fd, const int fdset[], size_t n_fdset) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_max_fd(void) {
|
int get_max_fd(void) {
|
||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
rlim_t m;
|
rlim_t m;
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(DIR*, closedir, NULL);
|
|||||||
int fd_nonblock(int fd, bool nonblock);
|
int fd_nonblock(int fd, bool nonblock);
|
||||||
int fd_cloexec(int fd, bool cloexec);
|
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(const int except[], size_t n_except);
|
||||||
int close_all_fds_without_malloc(const int except[], size_t n_except);
|
int close_all_fds_without_malloc(const int except[], size_t n_except);
|
||||||
|
|
||||||
|
@ -215,18 +215,18 @@ static size_t validate_fds(
|
|||||||
|
|
||||||
static void test_close_all_fds(void) {
|
static void test_close_all_fds(void) {
|
||||||
_cleanup_free_ int *fds = NULL, *keep = NULL;
|
_cleanup_free_ int *fds = NULL, *keep = NULL;
|
||||||
struct rlimit rl;
|
|
||||||
size_t n_fds, n_keep;
|
size_t n_fds, n_keep;
|
||||||
|
int max_fd;
|
||||||
|
|
||||||
log_info("/* %s */", __func__);
|
log_info("/* %s */", __func__);
|
||||||
|
|
||||||
rlimit_nofile_bump(-1);
|
rlimit_nofile_bump(-1);
|
||||||
|
|
||||||
assert_se(getrlimit(RLIMIT_NOFILE, &rl) >= 0);
|
max_fd = get_max_fd();
|
||||||
assert_se(rl.rlim_cur > 10);
|
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 */
|
/* 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 */
|
assert_se((n_fds & 1U) == 0U); /* make sure even number of fds */
|
||||||
|
|
||||||
/* Allocate the determined number of fds, always two at a time */
|
/* Allocate the determined number of fds, always two at a time */
|
||||||
|
Loading…
Reference in New Issue
Block a user