diff options
author | jilles <jilles@FreeBSD.org> | 2013-05-11 22:13:24 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2013-05-11 22:13:24 +0000 |
commit | a9655d0ad7ed70ca698f7ccad9b3f3f1ca949ced (patch) | |
tree | 44b185e77a3d7a30fde5b87c7bbae60efabf959f /tools/regression/file/dup/dup.c | |
parent | 2a5622a76f91bacfe554dfea1117a7b84273c585 (diff) | |
download | FreeBSD-src-a9655d0ad7ed70ca698f7ccad9b3f3f1ca949ced.zip FreeBSD-src-a9655d0ad7ed70ca698f7ccad9b3f3f1ca949ced.tar.gz |
Add simple testcases for fcntl(F_DUP2FD_CLOEXEC).
Diffstat (limited to 'tools/regression/file/dup/dup.c')
-rw-r--r-- | tools/regression/file/dup/dup.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/tools/regression/file/dup/dup.c b/tools/regression/file/dup/dup.c index bf403c0..6546147 100644 --- a/tools/regression/file/dup/dup.c +++ b/tools/regression/file/dup/dup.c @@ -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 <sys/types.h> @@ -68,7 +74,7 @@ main(int __unused argc, char __unused *argv[]) 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 *argv[]) 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); } |