/* Test if F_DUPFD_CLOEXEC works right. * by Richard W.M. Jones. */ #include #include #include #include #include int main () { char *file = "/tmp/cloexec.tmp"; int fd = creat (file, 0600); int fd2; int flags; assert (fd >= 0); fd2 = fcntl (fd, F_DUPFD_CLOEXEC, 0); assert (fd2 >= 0); flags = fcntl (fd2, F_GETFD); assert (flags >= 0); if ((flags & FD_CLOEXEC) == 0) { fprintf (stderr, "F_DUPFD_CLOEXEC failed to set FD_CLOEXEC flag!\n"); exit (EXIT_FAILURE); } exit (EXIT_SUCCESS); }