cvs: /php4/ext/session mod_files.sh /php4/ext/session mod_files.c
| From: | Sascha Schumann | Date: | Sun, 22 Aug 1999 14:14:46 +0000 |
| Subject: | cvs: /php4/ext/session mod_files.sh /php4/ext/session mod_files.c | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-3637@lists.php.net to get a copy of this message | ||
sas Sun Aug 22 10:14:46 1999 EDT
Added files:
/php4/ext/session mod_files.sh
Modified files:
/php4/ext/session mod_files.c
Log:
- cleanup code
- add script which creates the directory tree for better scaling
of mod_files
I have to decide yet whether we implement the garbage collection in the
module or if we simply let the user do
find path -ctime +1 | xargs rm
Index: php4/ext/session/mod_files.c
diff -u php4/ext/session/mod_files.c:1.10 php4/ext/session/mod_files.c:1.11
--- php4/ext/session/mod_files.c:1.10 Sun Aug 22 09:43:23 1999
+++ php4/ext/session/mod_files.c Sun Aug 22 10:14:46 1999
@@ -39,12 +39,10 @@
int dirdepth;
} ps_files;
-
ps_module ps_mod_files = {
PS_MOD(files)
};
-
#define PS_FILES_DATA ps_files *data = *mod_data
PS_OPEN_FUNC(files)
@@ -93,8 +91,14 @@
int keylen;
if(data->fd < 0 || !data->lastkey || strcmp(key, data->lastkey)) {
- if(data->lastkey) efree(data->lastkey);
- if(data->fd > -1) close(data->fd);
+ if(data->lastkey) {
+ efree(data->lastkey);
+ data->lastkey = NULL;
+ }
+ if(data->fd != -1) {
+ close(data->fd);
+ data->fd = -1;
+ }
keylen = strlen(key);
if(keylen <= data->dirdepth || MAXPATHLEN <
@@ -111,10 +115,11 @@
data->lastkey = estrdup(key);
#ifdef O_EXCL
- data->fd = open(buf, O_EXCL | O_RDWR | O_CREAT, 0600);
- /* -1, if file exists and access failed due to O_EXCL|O_CREAT */
+ /* in the common case, the file already exists */
+ data->fd = open(buf, O_EXCL | O_RDWR);
if(data->fd == -1) {
- data->fd = open(buf, O_EXCL | O_RDWR);
+ /* create it, if necessary */
+ data->fd = open(buf, O_EXCL | O_RDWR | O_CREAT, 0600);
}
#else
data->fd = open(buf, O_CREAT | O_RDWR, 0600);
@@ -132,8 +137,9 @@
PS_FILES_DATA;
_ps_files_open(data, key);
- if(data->fd < 0)
+ if(data->fd < 0) {
return FAILURE;
+ }
if(fstat(data->fd, &sbuf)) {
return FAILURE;
@@ -158,8 +164,9 @@
PS_FILES_DATA;
_ps_files_open(data, key);
- if(data->fd < 0)
+ if(data->fd < 0) {
return FAILURE;
+ }
ftruncate(data->fd, 0);
lseek(data->fd, 0, SEEK_SET);