From owner-svn-src-all@FreeBSD.ORG Sat May 11 16:31:41 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id E42DBFBE; Sat, 11 May 2013 16:31:41 +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 D66E5EF2; Sat, 11 May 2013 16:31:41 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r4BGVfY2065865; Sat, 11 May 2013 16:31:41 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r4BGVfO7065864; Sat, 11 May 2013 16:31:41 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201305111631.r4BGVfO7065864@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 11 May 2013 16:31:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r250513 - 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-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 May 2013 16:31:42 -0000 Author: jilles Date: Sat May 11 16:31:41 2013 New Revision: 250513 URL: http://svnweb.freebsd.org/changeset/base/250513 Log: Add simple testcases for fcntl(F_DUPFD_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 15:45:44 2013 (r250512) +++ head/tools/regression/file/dup/dup.c Sat May 11 16:31:41 2013 (r250513) @@ -29,6 +29,9 @@ * duped fd. * Test #17: check if fcntl(F_DUP2FD) to a fd > current maximum number of open * files limit work. + * 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. */ #include @@ -65,7 +68,7 @@ main(int __unused argc, char __unused *a orgfd = getafile(); - printf("1..17\n"); + printf("1..19\n"); /* If dup(2) ever work? */ if ((fd1 = dup(orgfd)) < 0) @@ -229,5 +232,24 @@ main(int __unused argc, char __unused *a printf("ok %d - fcntl(F_DUP2FD) didn't bypass NOFILE limit\n", test); + /* Does fcntl(F_DUPFD_CLOEXEC) work? */ + if ((fd2 = fcntl(fd1, F_DUPFD_CLOEXEC, 10)) < 0) + err(1, "fcntl(F_DUPFD_CLOEXEC)"); + if (fd2 < 10) + printf("not ok %d - fcntl(F_DUPFD_CLOEXEC) returned wrong fd %d\n", + ++test, fd2); + else + printf("ok %d - fcntl(F_DUPFD_CLOEXEC) works\n", ++test); + + /* Was close-on-exec cleared? */ + ++test; + if (fcntl(fd2, F_GETFD) != 1) + printf( + "not ok %d - fcntl(F_DUPFD_CLOEXEC) didn't set close-on-exec\n", + test); + else + printf("ok %d - fcntl(F_DUPFD_CLOEXEC) set close-on-exec\n", + test); + return (0); }