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