diff options
author | Eric Blake <ebb9@byu.net> | 2009-12-07 11:50:59 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-12-16 19:25:30 -0700 |
commit | 38f87b03c2763bb2af05ae98905b0ac8ba55b3eb (patch) | |
tree | 1ee5e48a45fd0aec3288652fdd1f195fc7474d51 /m4 | |
parent | 12126c1477f0ae1070c51ed76025f21cb6ea56e7 (diff) | |
download | gnulib-38f87b03c2763bb2af05ae98905b0ac8ba55b3eb.tar.gz |
fcntl: support F_DUPFD_CLOEXEC on systems with fcntl
Implement F_DUPFD_CLOEXEC. The unit test still fails on systems
with other fcntl bugs (such as cygwin 1.5 mishandling F_DUPFD,
or mingw lacking fcntl altogether). Passes on Linux, both with
and without kernel support, and on cygwin 1.7.
* modules/fcntl (Files): List new files.
(configure.ac): Run a test.
* m4/fcntl.m4 (gl_FUNC_FCNTL): New file.
* lib/fcntl.c (rpl_fcntl): Likewise.
* m4/fcntl_h.m4 (gl_FCNTL_H_DEFAULTS): Add witness defaults.
(gl_FCNTL_H): Always replace fcntl.h.
* modules/fcntl-h (Makefile.am): Substitute witnesses.
* lib/fcntl.in.h (fcntl): Declare replacement.
(F_DUPFD_CLOEXEC, GNULIB_defined_F_DUPFD_CLOEXEC): New macro when
needed, plus a witness.
* doc/posix-functions/fcntl.texi (fcntl): Document this.
* doc/posix-headers/fcntl.texi (fcntl.h): Likewise.
* tests/test-fcntl.c: New file.
* modules/fcntl-tests: Likewise.
Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'm4')
-rw-r--r-- | m4/fcntl.m4 | 49 | ||||
-rw-r--r-- | m4/fcntl_h.m4 | 6 |
2 files changed, 52 insertions, 3 deletions
diff --git a/m4/fcntl.m4 b/m4/fcntl.m4 new file mode 100644 index 0000000000..f361b7d578 --- /dev/null +++ b/m4/fcntl.m4 @@ -0,0 +1,49 @@ +# fcntl.m4 serial 1 +dnl Copyright (C) 2009 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +# For now, this module ensures that fcntl() +# - supports or emulates F_DUPFD_CLOEXEC +# Still to be ported to various platforms: +# - supports F_DUPFD correctly +# Still to be ported to mingw: +# - F_GETFD, F_SETFD, F_DUPFD +# - F_DUPFD_CLOEXEC +# - F_GETFL, F_SETFL +# - F_GETOWN, F_SETOWN +# - F_GETLK, F_SETLK, F_SETLKW +AC_DEFUN([gl_FUNC_FCNTL], +[ + dnl Persuade glibc to expose F_DUPFD_CLOEXEC. + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([fcntl]) + if test $ac_cv_func_fcntl = no; then + HAVE_FCNTL=0 + else + AC_CACHE_CHECK([whether fcntl understands F_DUPFD_CLOEXEC], + [gl_cv_func_fcntl_f_dupfd_cloexec], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include <fcntl.h> +#ifndef F_DUPFD_CLOEXEC +choke me +#endif + ]])], + [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#ifdef __linux__ +/* The Linux kernel only added F_DUPFD_CLOEXEC in 2.6.24, so we always replace + it to support the semantics on older kernels that failed with EINVAL. */ +choke me +#endif + ]])], + [gl_cv_func_fcntl_f_dupfd_cloexec=yes], + [gl_cv_func_fcntl_f_dupfd_cloexec="needs runtime check"])], + [gl_cv_func_fcntl_f_dupfd_cloexec=no])]) + if test "$gl_cv_func_fcntl_f_dupfd_cloexec" != yes; then + REPLACE_FCNTL=1 + AC_LIBOBJ([fcntl]) + fi + fi +]) diff --git a/m4/fcntl_h.m4 b/m4/fcntl_h.m4 index 40a18034dc..3825adf971 100644 --- a/m4/fcntl_h.m4 +++ b/m4/fcntl_h.m4 @@ -1,4 +1,4 @@ -# serial 6 +# serial 7 # Configure fcntl.h. dnl Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation @@ -12,8 +12,6 @@ AC_DEFUN([gl_FCNTL_H], AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) AC_REQUIRE([gl_FCNTL_O_FLAGS]) gl_CHECK_NEXT_HEADERS([fcntl.h]) - FCNTL_H='fcntl.h' - AC_SUBST([FCNTL_H]) ]) # Test whether the flags O_NOATIME and O_NOFOLLOW actually work. @@ -99,10 +97,12 @@ AC_DEFUN([gl_FCNTL_MODULE_INDICATOR], AC_DEFUN([gl_FCNTL_H_DEFAULTS], [ + GNULIB_FCNTL=0; AC_SUBST([GNULIB_FCNTL]) GNULIB_OPEN=0; AC_SUBST([GNULIB_OPEN]) GNULIB_OPENAT=0; AC_SUBST([GNULIB_OPENAT]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_OPENAT=1; AC_SUBST([HAVE_OPENAT]) + REPLACE_FCNTL=0; AC_SUBST([REPLACE_FCNTL]) REPLACE_OPEN=0; AC_SUBST([REPLACE_OPEN]) REPLACE_OPENAT=0; AC_SUBST([REPLACE_OPENAT]) ]) |