]> granicus.if.org Git - php/commitdiff
Improve locking when O_EXCL is available
authorSascha Schumann <sas@php.net>
Fri, 3 Dec 1999 16:19:38 +0000 (16:19 +0000)
committerSascha Schumann <sas@php.net>
Fri, 3 Dec 1999 16:19:38 +0000 (16:19 +0000)
ext/session/mod_files.c

index 1bd45245796c52f6dc6cd8cce03b8a95f9e2e68e..c2800b1604653233acaae797e9400afeddc56ecb 100644 (file)
@@ -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);