mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Refactor union semun in ext/sysvsem (#13473)
The union semun is always defined in php-src code. Current systems require user to define it manually as done in the ext/sysvsem/sysvsem.c. The conditional checks for HAVE_SEMUN were unused. The PHP 3.0.12 AIX bug bugs.php.net/2149 was fixed by the removal of __GNU_LIBRARY__ check, so this now further simplifies the code. The Autoconf AC_CHECK_TYPES checks if system by any chance has the union semun, and by default defines the HAVE_UNION_SEMUN.
This commit is contained in:
@@ -4,22 +4,9 @@ PHP_ARG_ENABLE([sysvsem],
|
||||
[Enable System V semaphore support])])
|
||||
|
||||
if test "$PHP_SYSVSEM" != "no"; then
|
||||
PHP_NEW_EXTENSION(sysvsem, sysvsem.c, $ext_shared)
|
||||
AC_DEFINE(HAVE_SYSVSEM, 1, [ ])
|
||||
AC_CACHE_CHECK(for union semun,php_cv_semun,
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
]], [[union semun x;]])],[
|
||||
php_cv_semun=yes
|
||||
],[
|
||||
php_cv_semun=no
|
||||
])
|
||||
)
|
||||
if test "$php_cv_semun" = "yes"; then
|
||||
AC_DEFINE(HAVE_SEMUN, 1, [ ])
|
||||
else
|
||||
AC_DEFINE(HAVE_SEMUN, 0, [ ])
|
||||
fi
|
||||
PHP_NEW_EXTENSION(sysvsem, sysvsem.c, $ext_shared)
|
||||
AC_DEFINE(HAVE_SYSVSEM, 1, [ ])
|
||||
AC_CHECK_TYPES([union semun],,,[#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>])
|
||||
fi
|
||||
|
||||
@@ -32,18 +32,13 @@
|
||||
#include "php_sysvsem.h"
|
||||
#include "ext/standard/info.h"
|
||||
|
||||
#if !HAVE_SEMUN
|
||||
|
||||
#ifndef HAVE_UNION_SEMUN
|
||||
union semun {
|
||||
int val; /* value for SETVAL */
|
||||
struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
|
||||
unsigned short int *array; /* array for GETALL, SETALL */
|
||||
struct seminfo *__buf; /* buffer for IPC_INFO */
|
||||
};
|
||||
|
||||
#undef HAVE_SEMUN
|
||||
#define HAVE_SEMUN 1
|
||||
|
||||
#endif
|
||||
|
||||
/* {{{ sysvsem_module_entry */
|
||||
@@ -173,12 +168,6 @@ PHP_MINFO_FUNCTION(sysvsem)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#define SETVAL_WANTS_PTR
|
||||
|
||||
#if defined(_AIX)
|
||||
#undef SETVAL_WANTS_PTR
|
||||
#endif
|
||||
|
||||
/* {{{ Return an id for the semaphore with the given key, and allow max_acquire (default 1) processes to acquire it simultaneously */
|
||||
PHP_FUNCTION(sem_get)
|
||||
{
|
||||
@@ -247,24 +236,11 @@ PHP_FUNCTION(sem_get)
|
||||
/* If we are the only user, then take this opportunity to set the max. */
|
||||
|
||||
if (count == 1) {
|
||||
#if HAVE_SEMUN
|
||||
/* This is correct for Linux which has union semun. */
|
||||
union semun semarg;
|
||||
semarg.val = max_acquire;
|
||||
if (semctl(semid, SYSVSEM_SEM, SETVAL, semarg) == -1) {
|
||||
php_error_docref(NULL, E_WARNING, "Failed for key 0x" ZEND_XLONG_FMT ": %s", key, strerror(errno));
|
||||
}
|
||||
#elif defined(SETVAL_WANTS_PTR)
|
||||
/* This is correct for Solaris 2.6 which does not have union semun. */
|
||||
if (semctl(semid, SYSVSEM_SEM, SETVAL, &max_acquire) == -1) {
|
||||
php_error_docref(NULL, E_WARNING, "Failed for key 0x%lx: %s", key, strerror(errno));
|
||||
}
|
||||
#else
|
||||
/* This works for i.e. AIX */
|
||||
if (semctl(semid, SYSVSEM_SEM, SETVAL, max_acquire) == -1) {
|
||||
php_error_docref(NULL, E_WARNING, "Failed for key 0x%lx: %s", key, strerror(errno));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Set semaphore 1 back to zero. */
|
||||
@@ -357,10 +333,8 @@ PHP_FUNCTION(sem_remove)
|
||||
{
|
||||
zval *arg_id;
|
||||
sysvsem_sem *sem_ptr;
|
||||
#if HAVE_SEMUN
|
||||
union semun un;
|
||||
struct semid_ds buf;
|
||||
#endif
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &arg_id, sysvsem_ce) == FAILURE) {
|
||||
RETURN_THROWS();
|
||||
@@ -368,21 +342,13 @@ PHP_FUNCTION(sem_remove)
|
||||
|
||||
sem_ptr = Z_SYSVSEM_P(arg_id);
|
||||
|
||||
#if HAVE_SEMUN
|
||||
un.buf = &buf;
|
||||
if (semctl(sem_ptr->semid, 0, IPC_STAT, un) < 0) {
|
||||
#else
|
||||
if (semctl(sem_ptr->semid, 0, IPC_STAT, NULL) < 0) {
|
||||
#endif
|
||||
php_error_docref(NULL, E_WARNING, "SysV semaphore for key 0x%x does not (any longer) exist", sem_ptr->key);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
#if HAVE_SEMUN
|
||||
if (semctl(sem_ptr->semid, 0, IPC_RMID, un) < 0) {
|
||||
#else
|
||||
if (semctl(sem_ptr->semid, 0, IPC_RMID, NULL) < 0) {
|
||||
#endif
|
||||
php_error_docref(NULL, E_WARNING, "Failed for SysV semaphore for key 0x%x: %s", sem_ptr->key, strerror(errno));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user