From: Sascha Schumann Date: Wed, 2 Oct 2002 06:05:16 +0000 (+0000) Subject: The pread/pwrite macros check for a bug in the Linux glibc now. X-Git-Tag: MODERN_SYMMETRIC_SESSION_BEHAVIOUR_20021003~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1dd35bddb25e4f88567c543d96418fe985afbd4;p=php The pread/pwrite macros check for a bug in the Linux glibc now. The bug causes the kernel not to return -1/EAGAIN. The new test case has been borrowed from the Linux Test Project. This also fixes a bug which apparently caused HAVE_PREAD/WRITE to be defined even if the more complex checks failed (ac_cv_func_NAME=no was set albeit with no difference). --- diff --git a/acinclude.m4 b/acinclude.m4 index 4b3221c637..3926bd08bf 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -381,7 +381,16 @@ AC_DEFUN(PHP_DOES_PWRITE_WORK,[ #include #include $1 - main() { return !(pwrite(open("conftest_in", O_WRONLY|O_CREAT, 0600), "hi", 2, 0) == 2); } + main() { + int fd = open("conftest_in", O_WRONLY|O_CREAT, 0600); + + if (fd < 0) exit(1); + if (pwrite(fd, "text", 4, 0) != 4) exit(1); + /* Linux glibc breakage until 2.2.5 */ + if (pwrite(fd, "text", 4, -1) != -1) exit(1); + exit(0); + } + ],[ ac_cv_pwrite=yes ],[ @@ -399,7 +408,15 @@ AC_DEFUN(PHP_DOES_PREAD_WORK,[ #include #include $1 - main() { char buf[3]; return !(pread(open("conftest_in", O_RDONLY), buf, 2, 0) == 2); } + main() { + char buf[3]; + int fd = open("conftest_in", O_RDONLY); + if (fd < 0) exit(1); + if (pread(fd, buf, 2, 0) != 2) exit(1); + /* Linux glibc breakage until 2.2.5 */ + if (pread(fd, buf, 2, -1) != -1) exit(1); + exit(0); + } ],[ ac_cv_pread=yes ],[ @@ -421,10 +438,12 @@ AC_DEFUN(PHP_PWRITE_TEST,[ fi ]) - case $ac_cv_pwrite in - no) ac_cv_func_pwrite=no;; - 64) AC_DEFINE(PHP_PWRITE_64, 1, [whether pwrite64 is default]);; - esac + if test "$ac_cv_pwrite" != "no"; then + AC_DEFINE(HAVE_PWRITE, 1, [ ]) + if test "$ac_cv_pwrite" = "64"; then + AC_DEFINE(PHP_PWRITE_64, 1, [whether pwrite64 is default]) + fi + fi ]) AC_DEFUN(PHP_PREAD_TEST,[ @@ -438,10 +457,12 @@ AC_DEFUN(PHP_PREAD_TEST,[ fi ]) - case $ac_cv_pread in - no) ac_cv_func_pread=no;; - 64) AC_DEFINE(PHP_PREAD_64, 1, [whether pread64 is default]);; - esac + if test "$ac_cv_pread" != "no"; then + AC_DEFINE(HAVE_PREAD, 1, [ ]) + if test "$ac_cv_pread" = "64"; then + AC_DEFINE(PHP_PREAD_64, 1, [whether pread64 is default]) + fi + fi ]) AC_DEFUN(PHP_MISSING_TIME_R_DECL,[ diff --git a/ext/session/config.m4 b/ext/session/config.m4 index 8bb43b676b..4e5a4ddd2c 100644 --- a/ext/session/config.m4 +++ b/ext/session/config.m4 @@ -9,7 +9,6 @@ PHP_ARG_WITH(mm,for mm support, [ --with-mm[=DIR] Include mm support for session storage], no, no) if test "$PHP_SESSION" != "no"; then - AC_CHECK_FUNCS(pread pwrite) PHP_PWRITE_TEST PHP_PREAD_TEST PHP_NEW_EXTENSION(session, session.c mod_files.c mod_mm.c mod_user.c, $ext_shared) diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 1a784e8b1e..541adbea91 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -271,7 +271,7 @@ PS_READ_FUNC(files) data->st_size = *vallen = sbuf.st_size; *val = emalloc(sbuf.st_size); -#if defined(HAVE_WORKING_PREAD_TEST) && defined(HAVE_PREAD) +#if defined(HAVE_PREAD) n = pread(data->fd, *val, sbuf.st_size, 0); #else lseek(data->fd, 0, SEEK_SET); @@ -307,7 +307,7 @@ PS_WRITE_FUNC(files) if (vallen < (int)data->st_size) ftruncate(data->fd, 0); -#if defined(HAVE_WORKING_PWRITE_TEST) && defined(HAVE_PWRITE) +#if defined(HAVE_PWRITE) n = pwrite(data->fd, val, vallen, 0); #else lseek(data->fd, 0, SEEK_SET);