From: Sascha Schumann Date: Fri, 3 Dec 1999 16:19:38 +0000 (+0000) Subject: Improve locking when O_EXCL is available X-Git-Tag: PRE_RETURN_REF_PATCH~104 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2e024a0005abf36965f1c50b02b3f1f27e3579d2;p=php Improve locking when O_EXCL is available --- 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);