Skip to content

Commit 9c42cd1

Browse files
committed
opcache: file_cache_read_only code review update (#16484)
1 parent c32b7ea commit 9c42cd1

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3305,35 +3305,40 @@ static zend_result accel_post_startup(void)
33053305
}
33063306

33073307
/* opcache.file_cache_read_only should only be enabled when all script files are read-only */
3308+
int file_cache_access_mode = 0;
3309+
33083310
if (ZCG(accel_directives).file_cache_read_only) {
33093311
if (!ZCG(accel_directives).file_cache) {
33103312
accel_startup_ok = false;
33113313
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "opcache.file_cache_read_only is set without a proper setting of opcache.file_cache");
33123314
return SUCCESS;
33133315
}
3314-
if (ZCG(accel_directives).revalidate_freq != 0) {
3315-
accel_startup_ok = false;
3316-
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "opcache.file_cache_read_only cannot be enabled when opcache.revalidate_freq is not 0.");
3317-
return SUCCESS;
3318-
}
3319-
if (ZCG(accel_directives).validate_timestamps) {
3320-
accel_startup_ok = false;
3321-
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "opcache.file_cache_read_only cannot be enabled when opcache.validate_timestamps is enabled.");
3322-
return SUCCESS;
3323-
}
3316+
3317+
/* opcache.file_cache is read only, so ensure the directory is readable */
3318+
#ifndef ZEND_WIN32
3319+
file_cache_access_mode = R_OK | X_OK;
3320+
#else
3321+
file_cache_access_mode = 04; // Read access
3322+
#endif
33243323
} else {
33253324
/* opcache.file_cache isn't read only, so ensure the directory is writable */
3326-
if ( ZCG(accel_directives).file_cache &&
33273325
#ifndef ZEND_WIN32
3328-
access(ZCG(accel_directives).file_cache, R_OK | W_OK | X_OK) != 0
3326+
file_cache_access_mode = R_OK | W_OK | X_OK;
33293327
#else
3330-
_access(ZCG(accel_directives).file_cache, 06) != 0
3328+
file_cache_access_mode = 06; // Read and write access
3329+
#endif
3330+
}
3331+
3332+
if ( ZCG(accel_directives).file_cache &&
3333+
#ifndef ZEND_WIN32
3334+
access(ZCG(accel_directives).file_cache, file_cache_access_mode) != 0
3335+
#else
3336+
_access(ZCG(accel_directives).file_cache, file_cache_access_mode) != 0
33313337
#endif
33323338
) {
3333-
accel_startup_ok = false;
3334-
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "opcache.file_cache must be a full path of an accessible, writable directory");
3335-
return SUCCESS;
3336-
}
3339+
accel_startup_ok = false;
3340+
zend_accel_error_noreturn(ACCEL_LOG_FATAL, "opcache.file_cache must be a full path of an accessible directory");
3341+
return SUCCESS;
33373342
}
33383343

33393344
#if ENABLE_FILE_CACHE_FALLBACK

ext/opcache/zend_accelerator_module.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,7 @@ static ZEND_INI_MH(OnUpdateFileCache)
170170

171171
if (!IS_ABSOLUTE_PATH(ZSTR_VAL(new_value), ZSTR_LEN(new_value)) ||
172172
zend_stat(ZSTR_VAL(new_value), &buf) != 0 ||
173-
!S_ISDIR(buf.st_mode) ||
174-
#ifndef ZEND_WIN32
175-
access(ZSTR_VAL(new_value), R_OK | X_OK) != 0) {
176-
#else
177-
_access(ZSTR_VAL(new_value), 04) != 0) {
178-
#endif
173+
!S_ISDIR(buf.st_mode)) {
179174
zend_accel_error(ACCEL_LOG_WARNING, "opcache.file_cache must be a full path of accessible directory.\n");
180175
new_value = NULL;
181176
}
@@ -311,10 +306,10 @@ ZEND_INI_BEGIN()
311306
STD_PHP_INI_ENTRY("opcache.mmap_base", NULL, PHP_INI_SYSTEM, OnUpdateString, accel_directives.mmap_base, zend_accel_globals, accel_globals)
312307
#endif
313308

314-
STD_PHP_INI_ENTRY("opcache.file_cache" , NULL , PHP_INI_SYSTEM, OnUpdateFileCache, accel_directives.file_cache, zend_accel_globals, accel_globals)
315-
STD_PHP_INI_BOOLEAN("opcache.file_cache_read_only" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_read_only, zend_accel_globals, accel_globals)
316-
STD_PHP_INI_BOOLEAN("opcache.file_cache_only" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_only, zend_accel_globals, accel_globals)
317-
STD_PHP_INI_BOOLEAN("opcache.file_cache_consistency_checks" , "1" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_consistency_checks, zend_accel_globals, accel_globals)
309+
STD_PHP_INI_ENTRY("opcache.file_cache" , NULL , PHP_INI_SYSTEM, OnUpdateFileCache, accel_directives.file_cache, zend_accel_globals, accel_globals)
310+
STD_PHP_INI_BOOLEAN("opcache.file_cache_read_only" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_read_only, zend_accel_globals, accel_globals)
311+
STD_PHP_INI_BOOLEAN("opcache.file_cache_only" , "0" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_only, zend_accel_globals, accel_globals)
312+
STD_PHP_INI_BOOLEAN("opcache.file_cache_consistency_checks" , "1" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_consistency_checks, zend_accel_globals, accel_globals)
318313
#if ENABLE_FILE_CACHE_FALLBACK
319314
STD_PHP_INI_BOOLEAN("opcache.file_cache_fallback" , "1" , PHP_INI_SYSTEM, OnUpdateBool, accel_directives.file_cache_fallback, zend_accel_globals, accel_globals)
320315
#endif

0 commit comments

Comments
 (0)