Module Name:    src
Committed By:   jruoho
Date:           Fri Apr  8 15:35:49 UTC 2011

Modified Files:
        src/tests/syscall: t_dup.c

Log Message:
Use RLIMIT_NOFILE rather than the static _SC_OPEN_MAX.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/syscall/t_dup.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/syscall/t_dup.c
diff -u src/tests/syscall/t_dup.c:1.2 src/tests/syscall/t_dup.c:1.3
--- src/tests/syscall/t_dup.c:1.2	Sun Apr  3 16:22:15 2011
+++ src/tests/syscall/t_dup.c	Fri Apr  8 15:35:49 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_dup.c,v 1.2 2011/04/03 16:22:15 jruoho Exp $ */
+/* $NetBSD: t_dup.c,v 1.3 2011/04/08 15:35:49 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,8 +29,9 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_dup.c,v 1.2 2011/04/03 16:22:15 jruoho Exp $");
+__RCSID("$NetBSD: t_dup.c,v 1.3 2011/04/08 15:35:49 jruoho Exp $");
 
+#include <sys/resource.h>
 #include <sys/stat.h>
 
 #include <errno.h>
@@ -63,6 +64,7 @@
 ATF_TC_BODY(dup_max, tc)
 {
 	int current, fd, *buf, serrno;
+	struct rlimit res;
 	long i, maxfd;
 
 	/*
@@ -71,9 +73,14 @@
 	 * reached. Ater that dup(2) should
 	 * fail with EMFILE.
 	 */
-	maxfd = sysconf(_SC_OPEN_MAX);
-	ATF_REQUIRE(maxfd >= 0);
+	(void)memset(&res, 0, sizeof(struct rlimit));
 
+	ATF_REQUIRE(getrlimit(RLIMIT_NOFILE, &res) == 0);
+
+	ATF_REQUIRE(res.rlim_cur > 0);
+	ATF_REQUIRE(res.rlim_max > 0);
+
+	maxfd = res.rlim_cur;
 	buf = calloc(maxfd, sizeof(int));
 
 	if (buf == NULL)
@@ -107,7 +114,7 @@
 	free(buf);
 
 	if (fd != -1 || serrno != EMFILE)
-		atf_tc_fail("dup(2) dupped more than _SC_OPEN_MAX");
+		atf_tc_fail("dup(2) dupped more than RLIMIT_NOFILE");
 }
 
 ATF_TC_CLEANUP(dup_max, tc)

Reply via email to