1 /*	$OpenBSD: rlim-file.c,v 1.3 2003/07/31 21:48:10 deraadt Exp $	*/
2 /*
3  *	Written by Artur Grabowski <art@openbsd.org> (2002) Public Domain.
4  */
5 #include <sys/types.h>
6 #include <sys/time.h>
7 #include <sys/resource.h>
8 #include <err.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <errno.h>
12 #include <string.h>
13 
14 int
15 main(int argc, char *argv[])
16 {
17 	int lim, fd, fds[2];
18 	struct rlimit rl;
19 
20 	if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
21 		err(1, "getrlimit");
22 
23 	lim = rl.rlim_cur;
24 
25 	fd = -1;
26 	while (fd < lim - 2)
27 		if ((fd = open("/dev/null", O_RDONLY)) < 0)
28 			err(1, "open");
29 
30 	if (pipe(fds) == 0)
31 		errx(1, "pipe was allowed");
32 
33 	if (errno == ENFILE)
34 		errx(1, "try to do the test on a less loaded system");
35 
36 	if (errno != EMFILE)
37 		errx(1, "bad errno (%d): %s", errno, strerror(errno));
38 
39 	return 0;
40 }
41 
42