/* $OpenBSD: rlim-file.c,v 1.2 2002/02/08 17:09:24 art Exp $ */ /* * Written by Artur Grabowski (2002) Public Domain. */ #include #include #include #include #include #include #include #include int main() { int lim, fd, fds[2]; struct rlimit rl; if (getrlimit(RLIMIT_NOFILE, &rl) < 0) err(1, "getrlimit"); lim = rl.rlim_cur; fd = -1; while (fd < lim - 2) if ((fd = open("/dev/null", O_RDONLY)) < 0) err(1, "open"); if (pipe(fds) == 0) errx(1, "pipe was allowed"); if (errno == ENFILE) errx(1, "try to do the test on a less loaded system"); if (errno != EMFILE) errx(1, "bad errno (%d): %s", errno, strerror(errno)); return 0; }