FD_CLOEXEC
if (fcntl(fd, F_SETFD, ret | FD_CLOEXEC) == -1)
# ifdef FD_CLOEXEC
# define set_cloexec_fd(FD) ((void)fcntl((FD), F_SETFD, FD_CLOEXEC))
fcntl (fd, F_SETFD, FD_CLOEXEC);
if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1 ||
(void)fcntl(rfd, F_SETFD, FD_CLOEXEC);
(void)fcntl(wfd, F_SETFD, FD_CLOEXEC);
(void)fcntl(efd, F_SETFD, FD_CLOEXEC);
if (fcntl(x, F_SETFD, FD_CLOEXEC) == -1) \
(void)fcntl(s, F_SETFD, FD_CLOEXEC);
(void)fcntl(sock, F_SETFD, FD_CLOEXEC);
fcntl(sock_out, F_SETFD, FD_CLOEXEC);
fcntl(sock_in, F_SETFD, FD_CLOEXEC);
fcntl(sock_out, F_SETFD, FD_CLOEXEC);
fcntl(sock_in, F_SETFD, FD_CLOEXEC);
if (fcntl(listen_sock, F_SETFD, FD_CLOEXEC) == -1) {
#if !defined(SOCK_CLOEXEC) && defined(FD_CLOEXEC)
return fcntl(fd, F_SETFD, FD_CLOEXEC) >= 0;
fdflags = ((flags & O_CLOEXEC) != 0 ? FD_CLOEXEC : 0) |
if ((flags & FD_CLOEXEC) == 0) {
rc = _fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
if ((tmp & FD_CLOEXEC) == 0) {
rc = _fcntl(fd, F_SETFD, tmp | FD_CLOEXEC);
if (fdflags != -1 && (fdflags & FD_CLOEXEC) == 0)
fdflags | FD_CLOEXEC);
exp_flags = FD_CLOEXEC;
ATF_CHECK_MSG((flags & FD_CLOEXEC) == exp_flags,
exp_fget_ret = strchr(mode, 'e') != NULL ? FD_CLOEXEC : 0;
(oflags & O_CLOEXEC ? FD_CLOEXEC : 0)) {
if (flags != -1 && (flags & FD_CLOEXEC) == 0)
(void)fcntl(sd, F_SETFD, flags | FD_CLOEXEC);
(void) fcntl(fds[i], F_SETFD, FD_CLOEXEC);
X(FD_CLOEXEC) X(FD_CLOFORK) X(0) XEND
if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) {
fcntl(fd_in, F_SETFD, fflags & ~FD_CLOEXEC);
(void)kern_fcntl(td, fd, F_SETFD, FD_CLOEXEC);
if ((flags & ~(FD_CLOEXEC | FD_CLOFORK)) != 0)
((flags & FD_CLOEXEC) != 0 ? FDDUP_FLAG_CLOEXEC : 0) |
{ .f = FD_CLOEXEC, .t = UF_EXCLOSE },
{ .f = UF_EXCLOSE, .t = FD_CLOEXEC },
"close-on-exec", FD_CLOEXEC, i >= 2 && i <= 5);
if (fcntl(fd2, F_GETFD) != FD_CLOEXEC)
if (fcntl(fd2, F_GETFD) != FD_CLOEXEC)
ATF_REQUIRE_MSG(fcntl(pathfd, F_SETFD, FD_CLOEXEC) == 0,
ATF_REQUIRE_MSG(fcntl(pathfd, F_GETFD) == FD_CLOEXEC,
ATF_REQUIRE_EQ_MSG(fcntl(getfd, F_GETFD) & FD_CLOEXEC, FD_CLOEXEC,
ATF_REQUIRE((fcntl(fd_nocl, F_GETFD) & FD_CLOEXEC) == 0);
ATF_REQUIRE((fcntl(fd_cl, F_GETFD) & FD_CLOEXEC) != 0);
ATF_REQUIRE((fcntl(fd, F_GETFD) & FD_CLOEXEC) != 0);
ATF_REQUIRE((fcntl(fd, F_GETFD) & FD_CLOEXEC) != 0);
(void)fcntl(fd, F_SETFD, FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_SETFD, FD_CLOEXEC) == 0);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
CHECK(fcntl(fd, F_GETFD) == FD_CLOEXEC);
pipe(spd) != 0 || fcntl(spd[1], F_SETFD, FD_CLOEXEC) != 0)