ext/opcache: check mkstemp() return value right after the call (#8031)

Don't call fchmod(-1), which is not only wrong, but also clobbers
errno and sets it to EBADF, breaking the following errno access for
the log message.
This commit is contained in:
Max Kellermann 2022-02-05 20:13:32 +01:00 committed by GitHub
parent 706398fa9f
commit 0199b22258
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,11 +83,12 @@ void zend_shared_alloc_create_lock(char *lockfile_path)
snprintf(lockfile_name, sizeof(lockfile_name), "%s/%sXXXXXX", lockfile_path, SEM_FILENAME_PREFIX);
lock_file = mkstemp(lockfile_name);
fchmod(lock_file, 0666);
if (lock_file == -1) {
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "Unable to create lock file: %s (%d)", strerror(errno), errno);
}
fchmod(lock_file, 0666);
val = fcntl(lock_file, F_GETFD, 0);
val |= FD_CLOEXEC;
fcntl(lock_file, F_SETFD, val);