Module Name:    src
Committed By:   njoly
Date:           Thu Oct 20 18:20:30 UTC 2011

Modified Files:
        src/tests/lib/libc/sys: t_pipe.c

Log Message:
New testcase that check for close-on-exec flag on pipe2 syscall.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/sys/t_pipe.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/lib/libc/sys/t_pipe.c
diff -u src/tests/lib/libc/sys/t_pipe.c:1.1 src/tests/lib/libc/sys/t_pipe.c:1.2
--- src/tests/lib/libc/sys/t_pipe.c:1.1	Sat Oct 15 06:17:02 2011
+++ src/tests/lib/libc/sys/t_pipe.c	Thu Oct 20 18:20:30 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: t_pipe.c,v 1.1 2011/10/15 06:17:02 jruoho Exp $ */
+/* $NetBSD: t_pipe.c,v 1.2 2011/10/20 18:20:30 njoly Exp $ */
 
 /*-
  * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -29,12 +29,13 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_pipe.c,v 1.1 2011/10/15 06:17:02 jruoho Exp $");
+__RCSID("$NetBSD: t_pipe.c,v 1.2 2011/10/20 18:20:30 njoly Exp $");
 
 #include <sys/types.h>
 #include <sys/wait.h>
 
 #include <errno.h>
+#include <fcntl.h>
 #include <poll.h>
 #include <sched.h>
 #include <signal.h>
@@ -154,9 +155,34 @@ ATF_TC_BODY(pipe_restart, tc)
 	}
 }
 
+ATF_TC(pipe2_cloexec);
+ATF_TC_HEAD(pipe2_cloexec, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Check pipe2(2) with O_CLOEXEC");
+}
+
+ATF_TC_BODY(pipe2_cloexec, tc)
+{
+	int flag, fildes[2];
+
+	ATF_REQUIRE(pipe2(fildes, O_CLOEXEC) != -1);
+
+	flag = fcntl(fildes[0], F_GETFD);
+	ATF_REQUIRE(flag != -1);
+	ATF_CHECK((flag & FD_CLOEXEC) != 0);
+
+	flag = fcntl(fildes[1], F_GETFD);
+	ATF_REQUIRE(flag != -1);
+	ATF_CHECK((flag & FD_CLOEXEC) != 0);
+
+	ATF_REQUIRE(close(fildes[0]) != -1);
+	ATF_REQUIRE(close(fildes[1]) != -1);
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, pipe_restart);
+	ATF_TP_ADD_TC(tp, pipe2_cloexec);
 
 	return atf_no_error();
 }

Reply via email to