From: Szabolcs Nagy Date: Sun, 13 Apr 2014 10:12:45 +0000 (+0200) Subject: rlimit regression test X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=a2e22ac14e13af5677a12bcf3c9583447615a4ff;p=libc-test rlimit regression test --- diff --git a/src/regression/rlimit-open-files.c b/src/regression/rlimit-open-files.c new file mode 100644 index 0000000..b946663 --- /dev/null +++ b/src/regression/rlimit-open-files.c @@ -0,0 +1,33 @@ +// rlimit should be able to set file limits +#include +#include +#include +#include +#include +#include "test.h" + +int main(void) +{ + static const long lim = 42; + static const int r = RLIMIT_NOFILE; + struct rlimit rl; + int fd, maxfd = 0; + + rl.rlim_max = lim; + rl.rlim_cur = lim; + if (setrlimit(r, &rl)) + t_error("setrlimit(%d, %ld) failed: %s\n", r, lim, strerror(errno)); + if (getrlimit(r, &rl)) + t_error("getrlimit(%d) failed: %s\n", r, strerror(errno)); + if (lim != rl.rlim_max || lim != rl.rlim_cur) + t_error("getrlimit %d says cur=%ld,max=%ld after setting the limit to %ld\n", r, rl.rlim_cur, rl.rlim_max, lim); + + while((fd=dup(1)) != -1) + if (fd > maxfd) maxfd = fd; + if (errno != EMFILE) + t_error("dup(1) failed with %s, wanted EMFILE\n", strerror(errno)); + if (maxfd+1 != lim) + t_error("more fds are open than rlimit allows: fd=%d, limit=%d\n", maxfd, lim); + + return t_status; +}