Skip to content

Commit 9ff6220

Browse files
crrodriguezdstogov
andauthored
opcache: Use O_TMPFILE file lock if available (#8634)
Use O_TMPFILE if the kernel supports it to create the lock fd, this has multiple advantages including not having to worry about naming, permissions and the assurance that it will always go away cleanly even on abnormal termination. Co-authored-by: Dmitry Stogov <[email protected]>
1 parent 36b194b commit 9ff6220

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

ext/opcache/zend_shared_alloc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ void zend_shared_alloc_create_lock(char *lockfile_path)
100100
return;
101101
#endif
102102

103+
#ifdef O_TMPFILE
104+
lock_file = open(lockfile_path, O_RDWR | O_TMPFILE | O_EXCL | O_CLOEXEC, 0666);
105+
/* lack of O_TMPFILE support results in many possible errors
106+
* use it only when open returns a non-negative integer */
107+
if (lock_file >= 0) {
108+
return;
109+
}
110+
#endif
111+
103112
snprintf(lockfile_name, sizeof(lockfile_name), "%s/%sXXXXXX", lockfile_path, SEM_FILENAME_PREFIX);
104113
lock_file = mkstemp(lockfile_name);
105114
if (lock_file == -1) {

0 commit comments

Comments
 (0)