diff options
| author | Sascha Schumann <sas@php.net> | 1999-12-03 16:19:38 +0000 |
|---|---|---|
| committer | Sascha Schumann <sas@php.net> | 1999-12-03 16:19:38 +0000 |
| commit | 2e024a0005abf36965f1c50b02b3f1f27e3579d2 (patch) | |
| tree | 56c093e89c14120dba6a5f0816d2a1699ac8aeca /ext/session/mod_files.c | |
| parent | c7b4d3cbf10b6d1b8b10623eb21e0377dadf417c (diff) | |
| download | php-git-2e024a0005abf36965f1c50b02b3f1f27e3579d2.tar.gz | |
Improve locking when O_EXCL is available
Diffstat (limited to 'ext/session/mod_files.c')
| -rw-r--r-- | ext/session/mod_files.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/session/mod_files.c b/ext/session/mod_files.c index 1bd4524579..c2800b1604 100644 --- a/ext/session/mod_files.c +++ b/ext/session/mod_files.c @@ -131,11 +131,13 @@ static void _ps_files_open(ps_files *data, const char *key) data->lastkey = estrdup(key); #ifdef O_EXCL - /* in the common case, the file already exists */ - data->fd = open(buf, O_EXCL | O_RDWR); - if(data->fd == -1) { - /* create it, if necessary */ - data->fd = open(buf, O_EXCL | O_RDWR | O_CREAT, 0600); + data->fd = open(buf, O_RDWR); + if (data->fd == -1) { + if (errno == ENOENT) { + data->fd = open(buf, O_EXCL | O_RDWR | O_CREAT, 0600); + } + } else { + flock(data->fd, LOCK_EX); } #else data->fd = open(buf, O_CREAT | O_RDWR, 0600); |
