1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or https://opensource.org/licenses/CDDL-1.0. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (C) 2015 STRATO AG. 24 */ 25 #include <err.h> 26 #include <fcntl.h> 27 #include <libzfs.h> 28 #include <sys/resource.h> 29 #include <sys/stat.h> 30 #include <sys/types.h> 31 #include <unistd.h> 32 33 /* 34 * Check if libzfs works with more than 255 held file handles. 35 */ 36 int 37 main(void) 38 { 39 struct rlimit limit = { 40 .rlim_cur = 64 * 1024, 41 .rlim_max = 64 * 1024, 42 }; 43 if (setrlimit(RLIMIT_NOFILE, &limit) != 0) 44 err(1, "setrlimit()"); 45 46 int fd = open("/dev/null", O_RDONLY); 47 if (fd == -1) 48 err(1, "open()"); 49 for (int i = 0; i < limit.rlim_cur / 2; ++i) 50 if (dup(fd) == -1) 51 err(1, "dup()"); 52 53 libzfs_handle_t *h = libzfs_init(); 54 if (h == NULL) 55 err(1, "libzfs_init()"); 56 57 libzfs_fini(h); 58 } 59