cvs: php4 / acinclude.m4 configure.in php_reentrancy.h reentrancy.c /ext/session/ mod_files.c /ext/standard/ dir.c
[email protected] ("Sascha Schumann")
| Newsgroups | php.version4 |
|---|---|
| Message-ID | <cvssas959094796@cvsserver> |
sas Tue May 23 17:13:16 2000 EDT
Modified files:
/php4 acinclude.m4 configure.in php_reentrancy.h reentrancy.c
/php4/ext/session mod_files.c
/php4/ext/standard dir.c
Log:
Use reentrant version of readdir. If the target platform does not support
the POSIX-like readdir_r, we fall back to readdir. In ZTS mode, this will
cause php_readdir_r calls to be serialized.
Index: php4/acinclude.m4
diff -u php4/acinclude.m4:1.85 php4/acinclude.m4:1.86
--- php4/acinclude.m4:1.85 Thu May 18 13:35:16 2000
+++ php4/acinclude.m4 Tue May 23 17:13:15 2000
@@ -1,8 +1,38 @@
-dnl $Id: acinclude.m4,v 1.85 2000/05/18 11:35:16 sas Exp $
+dnl $Id: acinclude.m4,v 1.86 2000/05/23 15:13:15 sas Exp $
dnl
dnl This file contains local autoconf functions.
sinclude(dynlib.m4)
+
+AC_DEFUN(PHP_POSIX_READDIR_R,[
+ AC_CACHE_CHECK(for type of readdir_r, ac_cv_what_readdir_r,[
+ AC_TRY_RUN([
+#include <sys/types.h>
+#include <dirent.h>
+
+main() {
+ DIR *dir;
+ struct dirent entry, *pentry;
+
+ dir = opendir("/");
+ if (!dir)
+ exit(1);
+ if (readdir_r(dir, &entry, &pentry) == 0)
+ exit(0);
+ exit(1);
+}
+ ],[
+ ac_cv_what_readdir_r=POSIX
+ ],[
+ ac_cv_what_readdir_r=none
+ ],[
+ ac_cv_what_readdir_r=none
+ ])
+ ])
+ if test "$ac_cv_what_readdir_r" = "POSIX"; then
+ AC_DEFINE(HAVE_POSIX_READDIR_R,1,[whether you have POSIX readdir_r])
+ fi
+])
AC_DEFUN(PHP_SHLIB_SUFFIX_NAME,[
PHP_SUBST(SHLIB_SUFFIX_NAME)
Index: php4/configure.in
diff -u php4/configure.in:1.133 php4/configure.in:1.134
--- php4/configure.in:1.133 Tue May 23 09:49:23 2000
+++ php4/configure.in Tue May 23 17:13:15 2000
@@ -1,4 +1,4 @@
-dnl ## $Id: configure.in,v 1.133 2000/05/23 07:49:23 thies Exp $ -*- sh -*-
+dnl ## $Id: configure.in,v 1.134 2000/05/23 15:13:15 sas Exp $ -*- sh -*-
dnl ## Process this file with autoconf to produce a configure script.
divert(1)
@@ -379,6 +379,7 @@
AC_BROKEN_SPRINTF
PHP_DECLARED_TIMEZONE
PHP_TIME_R_TYPE
+PHP_POSIX_READDIR_R
dnl AIX keeps in_addr_t in /usr/include/netinet/in.h
dnl AC_MSG_CHECKING(for in_addr_t)
Index: php4/php_reentrancy.h
diff -u php4/php_reentrancy.h:1.10 php4/php_reentrancy.h:1.11
--- php4/php_reentrancy.h:1.10 Thu May 18 17:34:21 2000
+++ php4/php_reentrancy.h Tue May 23 17:13:15 2000
@@ -22,6 +22,8 @@
#include "php.h"
+#include <sys/types.h>
+#include <dirent.h>
#include <time.h>
/* currently, PHP does not check for these functions, but assumes
@@ -38,6 +40,13 @@
#undef HAVE_ASCTIME_R
#undef HAVE_CTIME_R
#undef HAVE_GMTIME_R
+#endif
+
+#if defined(HAVE_POSIX_READDIR_R)
+#define php_readdir_r readdir_r
+#else
+PHPAPI int php_readdir_r(DIR *dirp, struct dirent *entry,
+ struct dirent **result);
#endif
#if !defined(HAVE_LOCALTIME_R) && defined(HAVE_LOCALTIME)
Index: php4/reentrancy.c
diff -u php4/reentrancy.c:1.15 php4/reentrancy.c:1.16
--- php4/reentrancy.c:1.15 Thu May 18 17:34:21 2000
+++ php4/reentrancy.c Tue May 23 17:13:15 2000
@@ -17,7 +17,17 @@
*/
+#include <sys/types.h>
#include <string.h>
+#include <errno.h>
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+
+#ifdef PHP_WIN32
+#define NEEDRDH 1
+#include "win32/readdir.h"
+#endif
#include "php_reentrancy.h"
#include "ext/standard/php_rand.h" /* for RAND_MAX */
@@ -27,6 +37,7 @@
CTIME_R,
ASCTIME_R,
GMTIME_R,
+ READDIR_R,
NUMBER_OF_LOCKS
};
@@ -77,7 +88,37 @@
}
#endif
+
+#if !defined(HAVE_POSIX_READDIR_R)
+
+PHPAPI int php_readdir_r(DIR *dirp, struct dirent *entry,
+ struct dirent **result)
+{
+ struct dirent *ptr;
+ int ret = 0;
+
+ local_lock(READDIR_R);
+
+ errno = 0;
+
+ ptr = readdir(dirp);
+ if (!ptr && errno != 0)
+ ret = errno;
+
+ if (entry && ptr)
+ memcpy(entry, ptr, sizeof(*ptr));
+
+ if (result)
+ *result = ptr;
+
+ local_unlock(READDIR_R);
+
+ return ret;
+}
+
+#endif
+
#if !defined(HAVE_LOCALTIME_R) && defined(HAVE_LOCALTIME)
PHPAPI struct tm *php_localtime_r(const time_t *const timep, struct tm *p_tm)
Index: php4/ext/session/mod_files.c
diff -u php4/ext/session/mod_files.c:1.33 php4/ext/session/mod_files.c:1.34
--- php4/ext/session/mod_files.c:1.33 Tue May 23 16:36:27 2000
+++ php4/ext/session/mod_files.c Tue May 23 17:13:15 2000
@@ -154,7 +154,7 @@
static int _ps_files_cleanup_dir(const char *dirname, int maxlifetime)
{
DIR *dir;
- struct dirent *entry;
+ struct dirent *entry, dentry;
struct stat sbuf;
char buf[MAXPATHLEN];
time_t now;
@@ -168,7 +168,7 @@
time(&now);
- while((entry = readdir(dir))) {
+ while (php_readdir_r(dir, &dentry, &entry) == 0 && entry) {
/* does the file start with our prefix? */
if (!strncmp(entry->d_name, FILE_PREFIX, sizeof(FILE_PREFIX) - 1) &&
/* create full path */
Index: php4/ext/standard/dir.c
diff -u php4/ext/standard/dir.c:1.33 php4/ext/standard/dir.c:1.34
--- php4/ext/standard/dir.c:1.33 Thu May 18 17:34:35 2000
+++ php4/ext/standard/dir.c Tue May 23 17:13:16 2000
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dir.c,v 1.33 2000/05/18 15:34:35 zeev Exp $ */
+/* $Id: dir.c,v 1.34 2000/05/23 15:13:16 sas Exp $ */
/* {{{ includes/startup/misc */
@@ -273,14 +273,14 @@
{
pval **id, **tmp, *myself;
php_dir *dirp;
- struct dirent *direntp;
+ struct dirent entry;
+ struct dirent *result;
DIRLS_FETCH();
FETCH_DIRP();
-
- direntp = readdir(dirp->dir);
- if (direntp) {
- RETURN_STRINGL(direntp->d_name, strlen(direntp->d_name), 1);
+
+ if (php_readdir_r(dirp->dir, &entry, &result) == 0 && result) {
+ RETURN_STRINGL(result->d_name, strlen(result->d_name), 1);
}
RETURN_FALSE;
}