tests: many_fds: simplify, modernise

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13411
This commit is contained in:
наб 2022-05-03 15:40:34 +02:00 committed by Brian Behlendorf
parent 510ee280c0
commit 951a3889d1
1 changed files with 20 additions and 34 deletions

View File

@ -22,15 +22,13 @@
/* /*
* Copyright (C) 2015 STRATO AG. * Copyright (C) 2015 STRATO AG.
*/ */
#include <stdlib.h> #include <err.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <libzfs.h> #include <libzfs.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <errno.h> #include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* /*
* Check if libzfs works with more than 255 held file handles. * Check if libzfs works with more than 255 held file handles.
@ -38,35 +36,23 @@
int int
main(void) main(void)
{ {
int i; struct rlimit limit = {
struct rlimit limit; .rlim_cur = 64 * 1024,
libzfs_handle_t *h; .rlim_max = 64 * 1024,
};
if (setrlimit(RLIMIT_NOFILE, &limit) != 0)
err(1, "setrlimit()");
limit.rlim_cur = 65535; int fd = open("/dev/null", O_RDONLY);
limit.rlim_max = 65535; if (fd == -1)
err(1, "open()");
for (int i = 0; i < limit.rlim_cur / 2; ++i)
if (dup(fd) == -1)
err(1, "dup()");
if (setrlimit(RLIMIT_NOFILE, &limit) != 0) { libzfs_handle_t *h = libzfs_init();
(void) printf("many_fds: setrlimit() failed with errno=%d\n", if (h == NULL)
errno); err(1, "libzfs_init()");
exit(1);
}
for (i = 0; i < 255; ++i) { libzfs_fini(h);
int fd = open("/dev/null", O_RDONLY);
if (fd == -1) {
(void) printf("open failed with errno=%d\n", errno);
return (1);
}
}
h = libzfs_init();
if (h != NULL) {
libzfs_fini(h);
return (0);
} else {
(void) printf("many_fds: libzfs_init() failed with errno=%d\n",
errno);
return (1);
}
} }