From owner-svn-src-head@FreeBSD.ORG Sat May 11 22:13:24 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id CDC153AA; Sat, 11 May 2013 22:13:24 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id A5B3BCB6; Sat, 11 May 2013 22:13:24 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4BMDO2w093396; Sat, 11 May 2013 22:13:24 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4BMDOT9093395; Sat, 11 May 2013 22:13:24 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201305112213.r4BMDOT9093395@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 11 May 2013 22:13:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250530 - head/tools/regression/file/dup X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 May 2013 22:13:24 -0000 Author: jilles Date: Sat May 11 22:13:24 2013 New Revision: 250530 URL: http://svnweb.freebsd.org/changeset/base/250530 Log: Add simple testcases for fcntl(F_DUP2FD_CLOEXEC). Modified: head/tools/regression/file/dup/dup.c Modified: head/tools/regression/file/dup/dup.c ============================================================================== --- head/tools/regression/file/dup/dup.c Sat May 11 21:23:55 2013 (r250529) +++ head/tools/regression/file/dup/dup.c Sat May 11 22:13:24 2013 (r250530) @@ -32,6 +32,12 @@ * Test #18: check if fcntl(F_DUPFD_CLOEXEC) works. * Test #19: check if fcntl(F_DUPFD_CLOEXEC) set close-on-exec flag for duped * fd. + * Test #20: check if fcntl(F_DUP2FD_CLOEXEC) works. + * Test #21: check if fcntl(F_DUP2FD_CLOEXEC) returned a fd we asked for. + * Test #22: check if fcntl(F_DUP2FD_CLOEXEC) set close-on-exec flag for duped + * fd. + * Test #23: check if fcntl(F_DUP2FD_CLOEXEC) to a fd > current maximum number + * of open files limit work. */ #include @@ -68,7 +74,7 @@ main(int __unused argc, char __unused *a orgfd = getafile(); - printf("1..19\n"); + printf("1..23\n"); /* If dup(2) ever work? */ if ((fd1 = dup(orgfd)) < 0) @@ -251,5 +257,45 @@ main(int __unused argc, char __unused *a printf("ok %d - fcntl(F_DUPFD_CLOEXEC) set close-on-exec\n", test); + /* If fcntl(F_DUP2FD_CLOEXEC) ever work? */ + if ((fd2 = fcntl(fd1, F_DUP2FD_CLOEXEC, fd1 + 1)) < 0) + err(1, "fcntl(F_DUP2FD_CLOEXEC)"); + printf("ok %d - fcntl(F_DUP2FD_CLOEXEC) works\n", ++test); + + /* Do we get the right fd? */ + ++test; + if (fd2 != fd1 + 1) + printf( + "no ok %d - fcntl(F_DUP2FD_CLOEXEC) didn't give us the right fd\n", + test); + else + printf("ok %d - fcntl(F_DUP2FD_CLOEXEC) returned a correct fd\n", + test); + + /* Was close-on-exec set? */ + ++test; + if (fcntl(fd2, F_GETFD) != FD_CLOEXEC) + printf( + "not ok %d - fcntl(F_DUP2FD_CLOEXEC) didn't set close-on-exec\n", + test); + else + printf("ok %d - fcntl(F_DUP2FD_CLOEXEC) set close-on-exec\n", + test); + + /* + * It is unclear what F_DUP2FD_CLOEXEC should do when duplicating a + * file descriptor onto itself. + */ + + ++test; + if (getrlimit(RLIMIT_NOFILE, &rlp) < 0) + err(1, "getrlimit"); + if ((fd2 = fcntl(fd1, F_DUP2FD_CLOEXEC, rlp.rlim_cur + 1)) >= 0) + printf("not ok %d - fcntl(F_DUP2FD_CLOEXEC) bypassed NOFILE limit\n", + test); + else + printf("ok %d - fcntl(F_DUP2FD_CLOEXEC) didn't bypass NOFILE limit\n", + test); + return (0); }