]> git.proxmox.com Git - mirror_zfs.git/commitdiff
tests: many_fds: simplify, modernise
authorнаб <nabijaczleweli@nabijaczleweli.xyz>
Tue, 3 May 2022 13:40:34 +0000 (15:40 +0200)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Wed, 11 May 2022 17:33:12 +0000 (10:33 -0700)
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13411

tests/zfs-tests/tests/functional/libzfs/many_fds.c

index 6def57c5a51a8e6e208464d4a9f638ab1c072eac..34029e0e32d0545b373e6360d094012c4a792959 100644 (file)
 /*
  * Copyright (C) 2015 STRATO AG.
  */
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <err.h>
 #include <fcntl.h>
 #include <libzfs.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.
 int
 main(void)
 {
-       int i;
-       struct rlimit limit;
-       libzfs_handle_t *h;
-
-       limit.rlim_cur = 65535;
-       limit.rlim_max = 65535;
-
-       if (setrlimit(RLIMIT_NOFILE, &limit) != 0) {
-               (void) printf("many_fds: setrlimit() failed with errno=%d\n",
-                   errno);
-               exit(1);
-       }
+       struct rlimit limit = {
+               .rlim_cur = 64 * 1024,
+               .rlim_max = 64 * 1024,
+       };
+       if (setrlimit(RLIMIT_NOFILE, &limit) != 0)
+               err(1, "setrlimit()");
 
-       for (i = 0; i < 255; ++i) {
-               int fd = open("/dev/null", O_RDONLY);
-               if (fd == -1) {
-                       (void) printf("open failed with errno=%d\n", errno);
-                       return (1);
-               }
-       }
+       int fd = open("/dev/null", O_RDONLY);
+       if (fd == -1)
+                       err(1, "open()");
+       for (int i = 0; i < limit.rlim_cur / 2; ++i)
+               if (dup(fd) == -1)
+                       err(1, "dup()");
 
-       h = libzfs_init();
+       libzfs_handle_t *h = libzfs_init();
+       if (h == NULL)
+               err(1, "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);
-       }
+       libzfs_fini(h);
 }