aboutsummaryrefslogtreecommitdiff
path: root/io
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-08-24 16:15:50 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-08-26 17:13:47 -0300
commit6b20880b22d1d0fce7e9f506baa6fe2d5c7fcfdc (patch)
tree626f478d869a5c26a0ae8b97f41b9d387e0e34b8 /io
parente814f4b04ee413a7bb3dfa43e74c8fb4abf58359 (diff)
downloadglibc-6b20880b22d1d0fce7e9f506baa6fe2d5c7fcfdc.zip
glibc-6b20880b22d1d0fce7e9f506baa6fe2d5c7fcfdc.tar.gz
glibc-6b20880b22d1d0fce7e9f506baa6fe2d5c7fcfdc.tar.bz2
Use support_open_dev_null_range io/tst-closefrom, misc/tst-close_range, and posix/tst-spawn5 (BZ #28260)
It ensures a continuous range of file descriptor and avoid hitting the RLIMIT_NOFILE. Checked on x86_64-linux-gnu.
Diffstat (limited to 'io')
-rw-r--r--io/tst-closefrom.c21
1 files changed, 6 insertions, 15 deletions
diff --git a/io/tst-closefrom.c b/io/tst-closefrom.c
index d4c1870..395ec0d 100644
--- a/io/tst-closefrom.c
+++ b/io/tst-closefrom.c
@@ -24,31 +24,22 @@
#include <support/check.h>
#include <support/descriptors.h>
#include <support/xunistd.h>
+#include <support/support.h>
#include <array_length.h>
#define NFDS 100
static int
-open_multiple_temp_files (void)
-{
- /* Check if the temporary file descriptor has no no gaps. */
- int lowfd = xopen ("/dev/null", O_RDONLY, 0600);
- for (int i = 1; i <= NFDS; i++)
- TEST_COMPARE (xopen ("/dev/null", O_RDONLY, 0600), lowfd + i);
- return lowfd;
-}
-
-static int
closefrom_test (void)
{
struct support_descriptors *descrs = support_descriptors_list ();
- int lowfd = open_multiple_temp_files ();
+ int lowfd = support_open_dev_null_range (NFDS, O_RDONLY, 0600);
- const int maximum_fd = lowfd + NFDS;
+ const int maximum_fd = lowfd + NFDS - 1;
const int half_fd = lowfd + NFDS / 2;
- const int gap = maximum_fd / 4;
+ const int gap = lowfd + NFDS / 4;
/* Close half of the descriptors and check result. */
closefrom (half_fd);
@@ -58,7 +49,7 @@ closefrom_test (void)
TEST_COMPARE (fcntl (i, F_GETFL), -1);
TEST_COMPARE (errno, EBADF);
}
- for (int i = 0; i < half_fd; i++)
+ for (int i = lowfd; i < half_fd; i++)
TEST_VERIFY (fcntl (i, F_GETFL) > -1);
/* Create some gaps, close up to a threshold, and check result. */
@@ -74,7 +65,7 @@ closefrom_test (void)
TEST_COMPARE (fcntl (i, F_GETFL), -1);
TEST_COMPARE (errno, EBADF);
}
- for (int i = 0; i < gap; i++)
+ for (int i = lowfd; i < gap; i++)
TEST_VERIFY (fcntl (i, F_GETFL) > -1);
/* Close the remmaining but the last one. */