From c15fe51918728816f65a78bbaf4090789aea71c4 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 2 Oct 2022 12:55:00 +0100 Subject: [PATCH] Fix GH-9653: does not inconditionally support copy_file_range on older kernels. As mentioned in its manpage, it had been reworked in the 5.3 line to support cross filesystem interactions. Closes #GH-9656 --- NEWS | 1 + configure.ac | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index b0a258b71b6..74f520b1490 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS - Streams: . Fixed bug GH-9590 (stream_select does not abort upon exception or empty valid fd set). (Arnaud) + . Fixed bug GH-9653 (file copy between different filesystems). (David Carlier) 29 Sep 2022, PHP 8.2.0RC3 diff --git a/configure.ac b/configure.ac index a9c609df2ed..331015490cf 100644 --- a/configure.ac +++ b/configure.ac @@ -364,7 +364,6 @@ PHP_CHECK_FUNC(socketpair, socket, network) PHP_CHECK_FUNC(htonl, socket, network) PHP_CHECK_FUNC(gethostname, nsl, network) PHP_CHECK_FUNC(gethostbyaddr, nsl, network) -PHP_CHECK_FUNC(copy_file_range) PHP_CHECK_FUNC(dlopen, dl, root) PHP_CHECK_FUNC(dlsym, dl, root) if test "$ac_cv_func_dlopen" = "yes"; then @@ -691,6 +690,33 @@ if test "$ac_cv_func_getaddrinfo" = yes; then AC_DEFINE(HAVE_GETADDRINFO,1,[Define if you have the getaddrinfo function]) fi +AC_CACHE_CHECK([for copy_file_range], ac_cv_copy_file_range, +[AC_RUN_IFELSE([AC_LANG_SOURCE([[ +#ifdef __linux__ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#include +#include + +int main(void) { +(void)copy_file_range(-1, 0, -1, 0, 0, 0); +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,3,0) +#error "kernel too old" +#else +return 0; +#endif +} +#else +#error "unsupported platform" +#endif +]])], [ac_cv_copy_file_range=yes], [ac_cv_copy_file_range=no]) +]) + +if test "$ac_cv_copy_file_range" = yes; then + AC_DEFINE(HAVE_COPY_FILE_RANGE,1,[Define if copy_file_range support]) +fi + AC_REPLACE_FUNCS(strlcat strlcpy explicit_bzero getopt) AC_FUNC_ALLOCA PHP_TIME_R_TYPE