summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Schumann <sas@php.net>2002-04-22 20:39:24 +0000
committerSascha Schumann <sas@php.net>2002-04-22 20:39:24 +0000
commit5a83ad6dc1648c33aa9b69c90e21c3a2475e085d (patch)
treea54eb308d3ec4bc968cce3d171f2d9abe92a2d82
parenta6117a874e86c8d586a1d585539a9d2d050c6c31 (diff)
downloadphp-git-5a83ad6dc1648c33aa9b69c90e21c3a2475e085d.tar.gz
Set the close-on-exec flag for fds. Child processes should not inherit
the fd. Also rip out the broken O_EXCL use. Our file names are not unique and this left a small window open where creating a session file would fail (a, b notice that the file does not exist; a creates the file successfully; b tries to create, but fails due to O_EXCL).
-rw-r--r--ext/session/mod_files.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c
index 9ca57b7eac..e3ef303611 100644
--- a/ext/session/mod_files.c
+++ b/ext/session/mod_files.c
@@ -141,20 +141,17 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
data->lastkey = estrdup(key);
-#ifdef O_EXCL
- data->fd = VCWD_OPEN(buf, O_RDWR | O_BINARY);
-
- if (data->fd == -1 && errno == ENOENT)
- data->fd = VCWD_OPEN_MODE(buf, O_EXCL | O_RDWR | O_CREAT | O_BINARY, 0600);
-#else
data->fd = VCWD_OPEN_MODE(buf, O_CREAT | O_RDWR | O_BINARY, 0600);
-#endif
- if (data->fd != -1)
+
+ if (data->fd != -1) {
flock(data->fd, LOCK_EX);
-
- if (data->fd == -1)
+ if (fcntl(data->fd, F_SETFD, 1)) {
+ php_error(E_WARNING, "fcntl(%d, F_SETFD, 1) failed: %s (%d)", data->fd, strerror(errno), errno);
+ }
+ } else {
php_error(E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf,
strerror(errno), errno);
+ }
}
}