Skip to content

Commit 9222702

Browse files
committed
Avoid dependency on "struct flock" fields order.
1 parent 186b5de commit 9222702

File tree

4 files changed

+56
-103
lines changed

4 files changed

+56
-103
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,12 @@ static inline void accel_restart_enter(void)
230230
#ifdef ZEND_WIN32
231231
INCREMENT(restart_in);
232232
#else
233-
# ifdef _AIX
234-
static FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
235-
# else
236-
static const FLOCK_STRUCTURE(restart_in_progress, F_WRLCK, SEEK_SET, 2, 1);
237-
#endif
233+
struct flock restart_in_progress;
234+
235+
restart_in_progress.l_type = F_WRLCK;
236+
restart_in_progress.l_whence = SEEK_SET;
237+
restart_in_progress.l_start = 2;
238+
restart_in_progress.l_len = 1;
238239

239240
if (fcntl(lock_file, F_SETLK, &restart_in_progress) == -1) {
240241
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC(+1): %s (%d)", strerror(errno), errno);
@@ -249,11 +250,12 @@ static inline void accel_restart_leave(void)
249250
ZCSG(restart_in_progress) = 0;
250251
DECREMENT(restart_in);
251252
#else
252-
# ifdef _AIX
253-
static FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
254-
# else
255-
static const FLOCK_STRUCTURE(restart_finished, F_UNLCK, SEEK_SET, 2, 1);
256-
# endif
253+
struct flock restart_finished;
254+
255+
restart_finished.l_type = F_UNLCK;
256+
restart_finished.l_whence = SEEK_SET;
257+
restart_finished.l_start = 2;
258+
restart_finished.l_len = 1;
257259

258260
ZCSG(restart_in_progress) = 0;
259261
if (fcntl(lock_file, F_SETLK, &restart_finished) == -1) {
@@ -266,7 +268,12 @@ static inline int accel_restart_is_active(void)
266268
{
267269
if (ZCSG(restart_in_progress)) {
268270
#ifndef ZEND_WIN32
269-
FLOCK_STRUCTURE(restart_check, F_WRLCK, SEEK_SET, 2, 1);
271+
struct flock restart_check;
272+
273+
restart_check.l_type = F_WRLCK;
274+
restart_check.l_whence = SEEK_SET;
275+
restart_check.l_start = 2;
276+
restart_check.l_len = 1;
270277

271278
if (fcntl(lock_file, F_GETLK, &restart_check) == -1) {
272279
zend_accel_error(ACCEL_LOG_DEBUG, "RestartC: %s (%d)", strerror(errno), errno);
@@ -291,11 +298,12 @@ static inline int accel_activate_add(void)
291298
#ifdef ZEND_WIN32
292299
INCREMENT(mem_usage);
293300
#else
294-
# ifdef _AIX
295-
static FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
296-
# else
297-
static const FLOCK_STRUCTURE(mem_usage_lock, F_RDLCK, SEEK_SET, 1, 1);
298-
# endif
301+
struct flock mem_usage_lock;
302+
303+
mem_usage_lock.l_type = F_RDLCK;
304+
mem_usage_lock.l_whence = SEEK_SET;
305+
mem_usage_lock.l_start = 1;
306+
mem_usage_lock.l_len = 1;
299307

300308
if (fcntl(lock_file, F_SETLK, &mem_usage_lock) == -1) {
301309
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(+1): %s (%d)", strerror(errno), errno);
@@ -314,11 +322,12 @@ static inline void accel_deactivate_sub(void)
314322
ZCG(counted) = 0;
315323
}
316324
#else
317-
# ifdef _AIX
318-
static FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
319-
# else
320-
static const FLOCK_STRUCTURE(mem_usage_unlock, F_UNLCK, SEEK_SET, 1, 1);
321-
# endif
325+
struct flock mem_usage_unlock;
326+
327+
mem_usage_unlock.l_type = F_UNLCK;
328+
mem_usage_unlock.l_whence = SEEK_SET;
329+
mem_usage_unlock.l_start = 1;
330+
mem_usage_unlock.l_len = 1;
322331

323332
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock) == -1) {
324333
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC(-1): %s (%d)", strerror(errno), errno);
@@ -331,11 +340,12 @@ static inline void accel_unlock_all(void)
331340
#ifdef ZEND_WIN32
332341
accel_deactivate_sub();
333342
#else
334-
# ifdef _AIX
335-
static FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
336-
# else
337-
static const FLOCK_STRUCTURE(mem_usage_unlock_all, F_UNLCK, SEEK_SET, 0, 0);
338-
# endif
343+
struct flock mem_usage_unlock_all;
344+
345+
mem_usage_unlock_all.l_type = F_UNLCK;
346+
mem_usage_unlock_all.l_whence = SEEK_SET;
347+
mem_usage_unlock_all.l_start = 0;
348+
mem_usage_unlock_all.l_len = 0;
339349

340350
if (fcntl(lock_file, F_SETLK, &mem_usage_unlock_all) == -1) {
341351
zend_accel_error(ACCEL_LOG_DEBUG, "UnlockAll: %s (%d)", strerror(errno), errno);
@@ -730,8 +740,12 @@ static inline int accel_is_inactive(void)
730740
return SUCCESS;
731741
}
732742
#else
733-
FLOCK_STRUCTURE(mem_usage_check, F_WRLCK, SEEK_SET, 1, 1);
743+
struct flock mem_usage_check;
734744

745+
mem_usage_check.l_type = F_WRLCK;
746+
mem_usage_check.l_whence = SEEK_SET;
747+
mem_usage_check.l_start = 1;
748+
mem_usage_check.l_len = 1;
735749
mem_usage_check.l_pid = -1;
736750
if (fcntl(lock_file, F_GETLK, &mem_usage_check) == -1) {
737751
zend_accel_error(ACCEL_LOG_DEBUG, "UpdateC: %s (%d)", strerror(errno), errno);

ext/opcache/ZendAccelerator.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@
8989
/*** file locking ***/
9090
#ifndef ZEND_WIN32
9191
extern int lock_file;
92-
93-
# if defined(HAVE_FLOCK_AIX64)
94-
# define FLOCK_STRUCTURE(name, type, whence, start, len) \
95-
struct flock name = {type, whence, 0, 0, 0, start, len }
96-
# elif defined(HAVE_FLOCK_BSD)
97-
# define FLOCK_STRUCTURE(name, type, whence, start, len) \
98-
struct flock name = {start, len, -1, type, whence}
99-
# elif defined(HAVE_FLOCK_LINUX)
100-
# define FLOCK_STRUCTURE(name, type, whence, start, len) \
101-
struct flock name = {type, whence, start, len}
102-
# else
103-
# error "Don't know how to define struct flock"
104-
# endif
10592
#endif
10693

10794
#if defined(HAVE_OPCACHE_FILE_CACHE) && defined(ZEND_WIN32)

ext/opcache/config.m4

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -343,63 +343,6 @@ int main() {
343343
msg=yes,msg=no,msg=no)
344344
AC_MSG_RESULT([$msg])
345345

346-
flock_type=unknown
347-
AC_MSG_CHECKING(for struct flock layout)
348-
349-
if test "$flock_type" = "unknown"; then
350-
AC_TRY_RUN([
351-
#include <fcntl.h>
352-
struct flock lock = { 1, 2, 3, 4, 5, 6, 7 };
353-
int main() {
354-
if(lock.l_type == 1 && lock.l_whence == 2 && lock.l_start == 6 && lock.l_len== 7) {
355-
return 0;
356-
}
357-
return 1;
358-
}
359-
], [
360-
flock_type=aix64
361-
AC_DEFINE([HAVE_FLOCK_AIX64], [], [Struct flock is 64-bit AIX-type])
362-
], [])
363-
fi
364-
365-
if test "$flock_type" = "unknown"; then
366-
AC_TRY_RUN([
367-
#include <fcntl.h>
368-
struct flock lock = { 1, 2, 3, 4, 5 };
369-
int main() {
370-
if(lock.l_type == 1 && lock.l_whence == 2 && lock.l_start == 3 && lock.l_len == 4) {
371-
return 0;
372-
}
373-
return 1;
374-
}
375-
], [
376-
flock_type=linux
377-
AC_DEFINE([HAVE_FLOCK_LINUX], [], [Struct flock is Linux-type])
378-
], [])
379-
fi
380-
381-
if test "$flock_type" = "unknown"; then
382-
AC_TRY_RUN([
383-
#include <fcntl.h>
384-
struct flock lock = { 1, 2, 3, 4, 5 };
385-
int main() {
386-
if(lock.l_start == 1 && lock.l_len == 2 && lock.l_type == 4 && lock.l_whence == 5) {
387-
return 0;
388-
}
389-
return 1;
390-
}
391-
], [
392-
flock_type=bsd
393-
AC_DEFINE([HAVE_FLOCK_BSD], [], [Struct flock is BSD-type])
394-
], [])
395-
fi
396-
397-
AC_MSG_RESULT([$flock_type])
398-
399-
if test "$flock_type" = "unknown"; then
400-
AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no])
401-
fi
402-
403346
PHP_NEW_EXTENSION(opcache,
404347
ZendAccelerator.c \
405348
zend_accelerator_blacklist.c \

ext/opcache/zend_shared_alloc.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ void zend_shared_alloc_safe_unlock(void)
371371
}
372372
}
373373

374-
#ifndef ZEND_WIN32
375-
/* name l_type l_whence l_start l_len */
376-
static FLOCK_STRUCTURE(mem_write_lock, F_WRLCK, SEEK_SET, 0, 1);
377-
static FLOCK_STRUCTURE(mem_write_unlock, F_UNLCK, SEEK_SET, 0, 1);
378-
#endif
379-
380374
void zend_shared_alloc_lock(void)
381375
{
382376
#ifndef ZEND_WIN32
377+
struct flock mem_write_lock;
378+
379+
mem_write_lock.l_type = F_WRLCK;
380+
mem_write_lock.l_whence = SEEK_SET;
381+
mem_write_lock.l_start = 0;
382+
mem_write_lock.l_len = 1;
383383

384384
#ifdef ZTS
385385
tsrm_mutex_lock(zts_lock);
@@ -410,6 +410,15 @@ void zend_shared_alloc_lock(void)
410410

411411
void zend_shared_alloc_unlock(void)
412412
{
413+
#ifndef ZEND_WIN32
414+
struct flock mem_write_unlock;
415+
416+
mem_write_unlock.l_type = F_UNLCK;
417+
mem_write_unlock.l_whence = SEEK_SET;
418+
mem_write_unlock.l_start = 0;
419+
mem_write_unlock.l_len = 1;
420+
#endif
421+
413422
ZCG(locked) = 0;
414423

415424
#ifndef ZEND_WIN32

0 commit comments

Comments
 (0)