cvs: php4 /ext/session mod_files.c
| From: | Sascha Schumann | Date: | Mon, 22 Apr 2002 20:39:25 +0000 |
| Subject: | cvs: php4 /ext/session mod_files.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-11316@lists.php.net to get a copy of this message | ||
sas Mon Apr 22 16:39:25 2002 EDT
Modified files:
/php4/ext/session mod_files.c
Log:
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).
Index: php4/ext/session/mod_files.c
diff -u php4/ext/session/mod_files.c:1.72 php4/ext/session/mod_files.c:1.73
--- php4/ext/session/mod_files.c:1.72 Wed Mar 6 06:49:51 2002
+++ php4/ext/session/mod_files.c Mon Apr 22 16:39:24 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: mod_files.c,v 1.72 2002/03/06 11:49:51 sas Exp $ */
+/* $Id: mod_files.c,v 1.73 2002/04/22 20:39:24 sas Exp $ */
#include "php.h"
@@ -141,20 +141,17 @@
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);
+ }
}
}