diff options
author | Sascha Schumann <sas@php.net> | 1999-08-22 14:14:46 +0000 |
---|---|---|
committer | Sascha Schumann <sas@php.net> | 1999-08-22 14:14:46 +0000 |
commit | 1dd31c38a6591f3f5744656249f40122511357ba (patch) | |
tree | dc6233b9974f91585d43af098854e3429f1cc138 | |
parent | 02d6ec2a6be6eb0ed297e92f8472f560ca572d3c (diff) | |
download | php-git-1dd31c38a6591f3f5744656249f40122511357ba.tar.gz |
- 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
-rw-r--r-- | ext/session/mod_files.c | 25 | ||||
-rw-r--r-- | ext/session/mod_files.sh | 16 |
2 files changed, 32 insertions, 9 deletions
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 65a91792cf..77e6ccd5ec 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -39,12 +39,10 @@ typedef struct { 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 @@ static void _ps_files_open(ps_files *data, const char *key) 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 @@ static void _ps_files_open(ps_files *data, const char *key) 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_READ_FUNC(files) 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_WRITE_FUNC(files) 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); diff --git a/ext/session/mod_files.sh b/ext/session/mod_files.sh new file mode 100644 index 0000000000..4d6a681d9c --- /dev/null +++ b/ext/session/mod_files.sh @@ -0,0 +1,16 @@ +#! /bin/sh + +if test "$2" = ""; then + echo "usage: $0 basedir depth" + exit 1 +fi + +if test "$2" = "0"; then + exit 0 +fi + +for i in a b c d e f 0 1 2 3 4 5 6 7 8 9; do + newpath="$1/$i" + mkdir $newpath || exit 1 + sh $0 $newpath `expr $2 - 1` +done |