diff --git a/tests/sys/posixshm/posixshm_test.c b/tests/sys/posixshm/posixshm_test.c index 05774df2b28..fd4101f6a84 100644 --- a/tests/sys/posixshm/posixshm_test.c +++ b/tests/sys/posixshm/posixshm_test.c @@ -609,6 +609,27 @@ ATF_TC_BODY(shm_functionality_across_fork, tc) shm_unlink(test_path); } +ATF_TC_WITHOUT_HEAD(cloexec); +ATF_TC_BODY(cloexec, tc) +{ + int fd; + + gen_test_path(); + + /* shm_open(2) is required to set FD_CLOEXEC */ + fd = shm_open(SHM_ANON, O_RDWR, 0777); + ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno); + ATF_REQUIRE((fcntl(fd, F_GETFD) & FD_CLOEXEC) != 0); + close(fd); + + /* Also make sure that named shm is correct */ + fd = shm_open(test_path, O_CREAT | O_RDWR, 0600); + ATF_REQUIRE_MSG(fd >= 0, "shm_open failed; errno=%d", errno); + ATF_REQUIRE((fcntl(fd, F_GETFD) & FD_CLOEXEC) != 0); + close(fd); +} + + ATF_TP_ADD_TCS(tp) { @@ -630,6 +651,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, unlink_bad_path_pointer); ATF_TP_ADD_TC(tp, unlink_path_too_long); ATF_TP_ADD_TC(tp, object_resize); + ATF_TP_ADD_TC(tp, cloexec); return (atf_no_error()); }