summaryrefslogtreecommitdiff
path: root/ext/session/mod_files.c
diff options
context:
space:
mode:
authorJani Taskinen <jani@php.net>2009-05-18 16:10:09 +0000
committerJani Taskinen <jani@php.net>2009-05-18 16:10:09 +0000
commit9ece649f7c64061fc874865ee9a1ab4a0161afce (patch)
treed4f486e070c60aedc10f4407eb30b1643a95c7dd /ext/session/mod_files.c
parent82c49a50f462e66af48ec7e25340f950beeb0ba8 (diff)
downloadphp-git-9ece649f7c64061fc874865ee9a1ab4a0161afce.tar.gz
MFH: ws + sync
Diffstat (limited to 'ext/session/mod_files.c')
-rw-r--r--ext/session/mod_files.c57
1 files changed, 25 insertions, 32 deletions
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c
index 555c67a375..80ea2c2a15 100644
--- a/ext/session/mod_files.c
+++ b/ext/session/mod_files.c
@@ -1,4 +1,4 @@
-/*
+/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
@@ -86,7 +86,7 @@ static int ps_files_valid_key(const char *key)
}
len = p - key;
-
+
if (len == 0) {
ret = 0;
}
@@ -100,7 +100,7 @@ static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, cons
const char *p;
int i;
int n;
-
+
key_len = strlen(key);
if (key_len <= data->dirdepth ||
buflen < (strlen(data->basedir) + 2 * data->dirdepth + key_len + 5 + sizeof(FILE_PREFIX))) {
@@ -120,18 +120,18 @@ static char *ps_files_path_create(char *buf, size_t buflen, ps_files *data, cons
memcpy(buf + n, key, key_len);
n += key_len;
buf[n] = '\0';
-
+
return buf;
}
#ifndef O_BINARY
-#define O_BINARY 0
-#endif
+# define O_BINARY 0
+#endif
static void ps_files_close(ps_files *data)
{
if (data->fd != -1) {
-#ifdef PHP_WIN32
+#ifdef PHP_WIN32
/* On Win32 locked files that are closed without being explicitly unlocked
will be unlocked only when "system resources become available". */
flock(data->fd, LOCK_UN);
@@ -177,13 +177,12 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
return;
}
if (
- S_ISLNK(sbuf.st_mode) &&
+ S_ISLNK(sbuf.st_mode) &&
(
php_check_open_basedir(buf TSRMLS_CC) ||
(PG(safe_mode) && !php_checkuid(buf, NULL, CHECKUID_CHECK_FILE_AND_DIR))
)
) {
-
close(data->fd);
return;
}
@@ -200,8 +199,7 @@ static void ps_files_open(ps_files *data, const char *key TSRMLS_DC)
}
#endif
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf,
- strerror(errno), errno);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "open(%s, O_RDWR) failed: %s (%d)", buf, strerror(errno), errno);
}
}
}
@@ -230,7 +228,7 @@ static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
/* Prepare buffer (dirname never changes) */
memcpy(buf, dirname, dirname_len);
buf[dirname_len] = PHP_DIR_SEPARATOR;
-
+
while (php_readdir_r(dir, (struct dirent *) dentry, &entry) == 0 && entry) {
/* does the file start with our prefix? */
if (!strncmp(entry->d_name, FILE_PREFIX, sizeof(FILE_PREFIX) - 1)) {
@@ -245,7 +243,7 @@ static int ps_files_cleanup_dir(const char *dirname, int maxlifetime TSRMLS_DC)
buf[dirname_len + entry_len + 1] = '\0';
/* check whether its last access was more than maxlifet ago */
- if (VCWD_STAT(buf, &sbuf) == 0 &&
+ if (VCWD_STAT(buf, &sbuf) == 0 &&
#ifdef NETWARE
(now - sbuf.st_mtime.tv_sec) > maxlifetime) {
#else
@@ -285,7 +283,7 @@ PS_OPEN_FUNC(files)
return FAILURE;
}
}
-
+
/* split up input parameter */
last = save_path;
p = strchr(save_path, ';');
@@ -305,7 +303,7 @@ PS_OPEN_FUNC(files)
return FAILURE;
}
}
-
+
if (argc > 2) {
errno = 0;
filemode = strtol(argv[1], NULL, 8);
@@ -316,17 +314,16 @@ PS_OPEN_FUNC(files)
}
save_path = argv[argc - 1];
- data = emalloc(sizeof(*data));
- memset(data, 0, sizeof(*data));
-
+ data = ecalloc(1, sizeof(*data));
+
data->fd = -1;
data->dirdepth = dirdepth;
data->filemode = filemode;
data->basedir_len = strlen(save_path);
data->basedir = estrndup(save_path, data->basedir_len);
-
+
PS_SET_MOD_DATA(data);
-
+
return SUCCESS;
}
@@ -387,7 +384,7 @@ PS_READ_FUNC(files)
efree(*val);
return FAILURE;
}
-
+
return SUCCESS;
}
@@ -401,11 +398,8 @@ PS_WRITE_FUNC(files)
return FAILURE;
}
- /*
- * truncate file, if the amount of new data is smaller than
- * the existing data set.
- */
-
+ /* Truncate file if the amount of new data is smaller than the existing data set. */
+
if (vallen < (int)data->st_size) {
ftruncate(data->fd, 0);
}
@@ -440,11 +434,10 @@ PS_DESTROY_FUNC(files)
if (data->fd != -1) {
ps_files_close(data);
-
+
if (VCWD_UNLINK(buf) == -1) {
/* This is a little safety check for instances when we are dealing with a regenerated session
- * that was not yet written to disk
- */
+ * that was not yet written to disk. */
if (!VCWD_ACCESS(buf, F_OK)) {
return FAILURE;
}
@@ -454,14 +447,14 @@ PS_DESTROY_FUNC(files)
return SUCCESS;
}
-PS_GC_FUNC(files)
+PS_GC_FUNC(files)
{
PS_FILES_DATA;
-
+
/* we don't perform any cleanup, if dirdepth is larger than 0.
we return SUCCESS, since all cleanup should be handled by
an external entity (i.e. find -ctime x | xargs rm) */
-
+
if (data->dirdepth == 0) {
*nrdels = ps_files_cleanup_dir(data->basedir, maxlifetime TSRMLS_CC);
}