diff --git a/Misc/NEWS.d/next/Build/2017-11-03-21-54-32.bpo-31940.fG1wnQ.rst b/Misc/NEWS.d/next/Build/2017-11-03-21-54-32.bpo-31940.fG1wnQ.rst new file mode 100644 index 00000000000000..3823fe6ec9711e --- /dev/null +++ b/Misc/NEWS.d/next/Build/2017-11-03-21-54-32.bpo-31940.fG1wnQ.rst @@ -0,0 +1,2 @@ +Detect faulty ``lchmod`` implementation to fix ``shutil.copystat`` on alpine +linux. Patch by Anthony Sottile. diff --git a/configure b/configure index 30df2cee70eea7..54a6420baad6be 100755 --- a/configure +++ b/configure @@ -11130,7 +11130,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ futimens futimes gai_strerror getentropy \ getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \ getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \ - initgroups kill killpg lchmod lchown linkat lstat lutimes mmap \ + initgroups kill killpg lchown linkat lstat lutimes mmap \ memrchr mbrtowc mkdirat mkfifo \ mkfifoat mknod mknodat mktime mremap nice openat pathconf pause pipe2 plock poll \ posix_fallocate posix_fadvise pread \ @@ -11837,6 +11837,60 @@ $as_echo "#define HAVE_LCHFLAGS 1" >>confdefs.h fi + +# on alpine, lchmod raises errno EOPNOTSUPP on symlinks +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for broken lchmod" >&5 +$as_echo_n "checking for broken lchmod... " >&6; } +if ${ac_cv_have_lchmod+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test "$cross_compiling" = yes; then : + ac_cv_have_lchmod=cross +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include +int main(int argc, char*argv[]) +{ + if (symlink(argv[0], "test")) + return 1; + if (lchmod("test", 0777)) + return 1; + return 0; +} + +_ACEOF +if ac_fn_c_try_run "$LINENO"; then : + ac_cv_have_lchmod=yes +else + ac_cv_have_lchmod=no +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \ + conftest.$ac_objext conftest.beam conftest.$ac_ext +fi + + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_have_lchmod" >&5 +$as_echo "$ac_cv_have_lchmod" >&6; } +if test "$ac_cv_have_lchmod" = cross ; then + ac_fn_c_check_func "$LINENO" "lchmod" "ac_cv_func_lchmod" +if test "x$ac_cv_func_lchmod" = xyes; then : + ac_cv_have_lchmod="yes" +else + ac_cv_have_lchmod="no" +fi + +fi +if test "$ac_cv_have_lchmod" = yes ; then + +$as_echo "#define HAVE_LCHMOD 1" >>confdefs.h + +fi +rm -f test + case $ac_sys_system/$ac_sys_release in Darwin/*) _CUR_CFLAGS="${CFLAGS}" diff --git a/configure.ac b/configure.ac index fd158681665ea8..7cf3f78c041db8 100644 --- a/configure.ac +++ b/configure.ac @@ -3405,7 +3405,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ futimens futimes gai_strerror getentropy \ getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \ getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \ - initgroups kill killpg lchmod lchown linkat lstat lutimes mmap \ + initgroups kill killpg lchown linkat lstat lutimes mmap \ memrchr mbrtowc mkdirat mkfifo \ mkfifoat mknod mknodat mktime mremap nice openat pathconf pause pipe2 plock poll \ posix_fallocate posix_fadvise pread \ @@ -3600,6 +3600,30 @@ if test "$ac_cv_have_lchflags" = yes ; then AC_DEFINE(HAVE_LCHFLAGS, 1, [Define to 1 if you have the 'lchflags' function.]) fi + +# on alpine, lchmod raises errno EOPNOTSUPP on symlinks +AC_CACHE_CHECK([for broken lchmod], [ac_cv_have_lchmod], [dnl +AC_RUN_IFELSE([AC_LANG_SOURCE([[ +#include +#include +int main(int argc, char*argv[]) +{ + if (symlink(argv[0], "test")) + return 1; + if (lchmod("test", 0777)) + return 1; + return 0; +} +]])],[ac_cv_have_lchmod=yes],[ac_cv_have_lchmod=no],[ac_cv_have_lchmod=cross]) +]) +if test "$ac_cv_have_lchmod" = cross ; then + AC_CHECK_FUNC([lchmod], [ac_cv_have_lchmod="yes"], [ac_cv_have_lchmod="no"]) +fi +if test "$ac_cv_have_lchmod" = yes ; then + AC_DEFINE(HAVE_LCHMOD, 1, [Define to 1 if you have the `lchmod' function.]) +fi +rm -f test + dnl Check if system zlib has *Copy() functions dnl dnl On MacOSX the linker will search for dylibs on the entire linker path