mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-01-23 10:36:42 +01:00
test: Fix closefrom() test to handle open file descriptor limits
If the system has configured a lower limit (either soft or hard) on the number of open file descriptors, the test will fail. Make sure to check whether we have exceeded that limit and adapt the max number of file descriptors appropriately.
This commit is contained in:
parent
07192b31e3
commit
0f8bcdfd92
@ -35,18 +35,28 @@ main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
int fd_max;
|
||||
|
||||
fd = open("/dev/null", O_RDONLY);
|
||||
|
||||
for (i = 4; i < 1024; i *= 2)
|
||||
assert(dup2(fd, i) == i);
|
||||
fd_max = 1024;
|
||||
for (i = 4; i < fd_max; i *= 2) {
|
||||
int fd_new = dup2(fd, i);
|
||||
|
||||
if (fd_new < 0 && (errno == EMFILE || errno == EBADF)) {
|
||||
fd_max = i - 1;
|
||||
break;
|
||||
}
|
||||
assert(fd_new == i);
|
||||
}
|
||||
|
||||
if (fd < 4)
|
||||
close(fd);
|
||||
closefrom(4);
|
||||
|
||||
for (i = 4; i < 1024; i++)
|
||||
for (i = 4; i < fd_max; i++) {
|
||||
assert(fcntl(i, F_GETFL) == -1 && errno == EBADF);
|
||||
}
|
||||
assert(fcntl(fd, F_GETFL) == -1 && errno == EBADF);
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user