diff options
author | jilles <jilles@FreeBSD.org> | 2013-05-11 16:31:41 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2013-05-11 16:31:41 +0000 |
commit | 94f06f64c9eb6004f1ff06649a15632fb2f98da4 (patch) | |
tree | 33d2b3b1d59532983d67fb112db325e03626978b /tools | |
parent | be2bfc68fd41b5efd65c981699e2c55b0a7a63fb (diff) | |
download | FreeBSD-src-94f06f64c9eb6004f1ff06649a15632fb2f98da4.zip FreeBSD-src-94f06f64c9eb6004f1ff06649a15632fb2f98da4.tar.gz |
Add simple testcases for fcntl(F_DUPFD_CLOEXEC).
Diffstat (limited to 'tools')
-rw-r--r-- | tools/regression/file/dup/dup.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/regression/file/dup/dup.c b/tools/regression/file/dup/dup.c index 73302d6..bf403c0 100644 --- a/tools/regression/file/dup/dup.c +++ b/tools/regression/file/dup/dup.c @@ -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 <sys/types.h> @@ -65,7 +68,7 @@ main(int __unused argc, char __unused *argv[]) 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 *argv[]) 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); } |