1999-04-22 10:48:28 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
| PHP Version 4 |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 16:29:35 +08:00
|
|
|
| Copyright (c) 1997-2002 The PHP Group |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 16:29:35 +08:00
|
|
|
| Authors: Tom May <tom@go2net.com> |
|
2001-05-15 15:29:31 +08:00
|
|
|
| Gavin Sherry <gavin@linuxworld.com.au> |
|
1999-04-22 10:48:28 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
2001-05-15 15:29:31 +08:00
|
|
|
/* Latest update build anc tested on Linux 2.2.14
|
|
|
|
*
|
|
|
|
* This has been built and tested on Solaris 2.6 and Linux 2.1.122.
|
1999-04-22 10:48:28 +08:00
|
|
|
* It may not compile or execute correctly on other systems.
|
|
|
|
*
|
|
|
|
* sas: Works for me on Linux 2.0.36 and FreeBSD 3.0-current
|
|
|
|
*/
|
|
|
|
|
2001-05-24 18:07:29 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1999-05-21 16:20:13 +08:00
|
|
|
#include "php.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
#if HAVE_SYSVSEM
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/sem.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
1999-12-05 03:19:57 +08:00
|
|
|
#include "php_sysvsem.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2000-04-14 21:14:30 +08:00
|
|
|
#if !HAVE_SEMUN
|
1999-05-21 16:04:38 +08:00
|
|
|
|
|
|
|
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
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ sysvsem_functions[]
|
|
|
|
*/
|
1999-04-22 10:48:28 +08:00
|
|
|
function_entry sysvsem_functions[] = {
|
1999-12-18 12:01:20 +08:00
|
|
|
PHP_FE(sem_get, NULL)
|
|
|
|
PHP_FE(sem_acquire, NULL)
|
|
|
|
PHP_FE(sem_release, NULL)
|
2001-05-15 15:29:31 +08:00
|
|
|
PHP_FE(sem_remove, NULL)
|
1999-04-22 10:48:28 +08:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ sysvsem_module_entry
|
|
|
|
*/
|
1999-05-21 16:20:13 +08:00
|
|
|
zend_module_entry sysvsem_module_entry = {
|
2001-10-12 07:33:59 +08:00
|
|
|
STANDARD_MODULE_HEADER,
|
|
|
|
"sysvsem", sysvsem_functions, PHP_MINIT(sysvsem), NULL, NULL, NULL, NULL, NO_VERSION_YET, STANDARD_MODULE_PROPERTIES
|
1999-04-22 10:48:28 +08:00
|
|
|
};
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2000-05-23 17:33:51 +08:00
|
|
|
#ifdef COMPILE_DL_SYSVSEM
|
2000-05-02 08:30:36 +08:00
|
|
|
ZEND_GET_MODULE(sysvsem)
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-12-18 12:01:20 +08:00
|
|
|
THREAD_LS sysvsem_module php_sysvsem_module;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
/* Semaphore functions using System V semaphores. Each semaphore
|
|
|
|
* actually consists of three semaphores allocated as a unit under the
|
|
|
|
* same key. Semaphore 0 (SYSVSEM_SEM) is the actual semaphore, it is
|
|
|
|
* initialized to max_acquire and decremented as processes acquire it.
|
|
|
|
* The value of semaphore 1 (SYSVSEM_USAGE) is a count of the number
|
|
|
|
* of processes using the semaphore. After calling semget(), if a
|
|
|
|
* process finds that the usage count is 1, it will set the value of
|
|
|
|
* SYSVSEM_SEM to max_acquire. This allows max_acquire to be set and
|
|
|
|
* track the PHP code without having a global init routine or external
|
|
|
|
* semaphore init code. Except see the bug regarding a race condition
|
1999-12-18 12:01:20 +08:00
|
|
|
* php_sysvsem_get(). Semaphore 2 (SYSVSEM_SETVAL) serializes the
|
1999-04-22 10:48:28 +08:00
|
|
|
* calls to GETVAL SYSVSEM_USAGE and SETVAL SYSVSEM_SEM. It can be
|
|
|
|
* acquired only when it is zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SYSVSEM_SEM 0
|
|
|
|
#define SYSVSEM_USAGE 1
|
|
|
|
#define SYSVSEM_SETVAL 2
|
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ release_sysvsem_sem
|
|
|
|
*/
|
2001-07-31 13:44:11 +08:00
|
|
|
static void release_sysvsem_sem(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
sysvsem_sem *sem_ptr = (sysvsem_sem *)rsrc->ptr;
|
1999-04-22 10:48:28 +08:00
|
|
|
struct sembuf sop[2];
|
2002-05-17 20:33:49 +08:00
|
|
|
int opcount = 1;
|
2001-05-15 15:29:31 +08:00
|
|
|
/*
|
|
|
|
* if count == -1, semaphore has been removed
|
|
|
|
* Need better way to handle this
|
|
|
|
*/
|
|
|
|
|
2002-05-17 20:33:49 +08:00
|
|
|
if(sem_ptr->count == -1 || !sem_ptr->auto_release) {
|
2002-09-27 18:24:54 +08:00
|
|
|
efree(sem_ptr);
|
2001-05-15 15:29:31 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
/* Decrement the usage count. */
|
|
|
|
|
|
|
|
sop[0].sem_num = SYSVSEM_USAGE;
|
|
|
|
sop[0].sem_op = -1;
|
|
|
|
sop[0].sem_flg = SEM_UNDO;
|
|
|
|
|
|
|
|
/* Release the semaphore if it has been acquired but not released. */
|
|
|
|
|
|
|
|
if (sem_ptr->count) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "Releasing SysV semaphore id %d key 0x%x in request cleanup", sem_ptr->id, sem_ptr->key);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
sop[1].sem_num = SYSVSEM_SEM;
|
|
|
|
sop[1].sem_op = sem_ptr->count;
|
|
|
|
sop[1].sem_flg = SEM_UNDO;
|
2002-05-17 20:33:49 +08:00
|
|
|
|
|
|
|
opcount++;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2002-05-17 20:33:49 +08:00
|
|
|
if (semop(sem_ptr->semid, sop, opcount) == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semop() failed in release_sysvsem_sem for key 0x%x: %s", sem_ptr->key, strerror(errno));
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
efree(sem_ptr);
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
|
|
|
*/
|
1999-12-18 12:01:20 +08:00
|
|
|
PHP_MINIT_FUNCTION(sysvsem)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
2000-10-26 01:44:02 +08:00
|
|
|
php_sysvsem_module.le_sem = zend_register_list_destructors_ex(release_sysvsem_sem, NULL, "sysvsem", module_number);
|
1999-04-22 10:48:28 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
1999-08-26 00:53:57 +08:00
|
|
|
#define SETVAL_WANTS_PTR
|
|
|
|
|
|
|
|
#if defined(_AIX)
|
|
|
|
#undef SETVAL_WANTS_PTR
|
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2002-05-17 20:33:49 +08:00
|
|
|
/* {{{ proto int sem_get(int key [, int max_acquire [, int perm [, int auto_release]])
|
2000-02-24 22:43:53 +08:00
|
|
|
Return an id for the semaphore with the given key, and allow max_acquire (default 1) processes to acquire it simultaneously */
|
1999-12-18 12:01:20 +08:00
|
|
|
PHP_FUNCTION(sem_get)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
2002-05-17 20:33:49 +08:00
|
|
|
int key, max_acquire, perm, auto_release = 1;
|
1999-04-22 10:48:28 +08:00
|
|
|
int semid;
|
|
|
|
struct sembuf sop[3];
|
|
|
|
int count;
|
|
|
|
sysvsem_sem *sem_ptr;
|
|
|
|
#if HAVE_SEMUN
|
|
|
|
union semun un;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
max_acquire = 1;
|
|
|
|
perm = 0666;
|
|
|
|
|
2002-05-17 20:33:49 +08:00
|
|
|
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|lll", &key, &max_acquire, &perm, &auto_release)) {
|
|
|
|
RETURN_FALSE;
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get/create the semaphore. Note that we rely on the semaphores
|
|
|
|
* being zeroed when they are created. Despite the fact that
|
|
|
|
* the(?) Linux semget() man page says they are not initialized,
|
|
|
|
* the kernel versions 2.0.x and 2.1.z do in fact zero them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
semid = semget(key, 3, perm|IPC_CREAT);
|
|
|
|
if (semid == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semget() failed for key 0x%x: %s", key, strerror(errno));
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find out how many processes are using this semaphore. Note
|
|
|
|
* that on Linux (at least) there is a race condition here because
|
|
|
|
* semaphore undo on process exit is not atomic, so we could
|
|
|
|
* acquire SYSVSEM_SETVAL before a crashed process has decremented
|
|
|
|
* SYSVSEM_USAGE in which case count will be greater than it
|
|
|
|
* should be and we won't set max_acquire. Fortunately this
|
|
|
|
* doesn't actually matter in practice.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Wait for sem 1 to be zero . . . */
|
|
|
|
|
|
|
|
sop[0].sem_num = SYSVSEM_SETVAL;
|
|
|
|
sop[0].sem_op = 0;
|
|
|
|
sop[0].sem_flg = 0;
|
|
|
|
|
|
|
|
/* . . . and increment it so it becomes non-zero . . . */
|
|
|
|
|
|
|
|
sop[1].sem_num = SYSVSEM_SETVAL;
|
|
|
|
sop[1].sem_op = 1;
|
|
|
|
sop[1].sem_flg = SEM_UNDO;
|
|
|
|
|
|
|
|
/* . . . and increment the usage count. */
|
|
|
|
|
|
|
|
sop[2].sem_num = SYSVSEM_USAGE;
|
|
|
|
sop[2].sem_op = 1;
|
|
|
|
sop[2].sem_flg = SEM_UNDO;
|
|
|
|
while (semop(semid, sop, 3) == -1) {
|
|
|
|
if (errno != EINTR) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semop() failed acquiring SYSVSEM_SETVAL for key 0x%x: %s", key, strerror(errno));
|
1999-04-22 10:48:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the usage count. */
|
|
|
|
#if HAVE_SEMUN
|
|
|
|
count = semctl(semid, SYSVSEM_USAGE, GETVAL, un);
|
|
|
|
#else
|
|
|
|
count = semctl(semid, SYSVSEM_USAGE, GETVAL, NULL);
|
|
|
|
#endif
|
|
|
|
if (count == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semctl(GETVAL) failed for key 0x%x: %s", key, strerror(errno));
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semctl(SETVAL) failed for key 0x%x: %s", key, strerror(errno));
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
1999-08-26 00:53:57 +08:00
|
|
|
#elif defined(SETVAL_WANTS_PTR)
|
1999-04-22 10:48:28 +08:00
|
|
|
/* This is correct for Solaris 2.6 which does not have union semun. */
|
|
|
|
if (semctl(semid, SYSVSEM_SEM, SETVAL, &max_acquire) == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semctl(SETVAL) failed for key 0x%x: %s", key, strerror(errno));
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
1999-08-26 00:53:57 +08:00
|
|
|
#else
|
|
|
|
/* This works for i.e. AIX */
|
|
|
|
if (semctl(semid, SYSVSEM_SEM, SETVAL, max_acquire) == -1) {
|
|
|
|
php_error(E_WARNING, "semctl(SETVAL) failed for key 0x%x: %s", key, strerror(errno));
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set semaphore 1 back to zero. */
|
|
|
|
|
|
|
|
sop[0].sem_num = SYSVSEM_SETVAL;
|
|
|
|
sop[0].sem_op = -1;
|
|
|
|
sop[0].sem_flg = SEM_UNDO;
|
|
|
|
while (semop(semid, sop, 1) == -1) {
|
|
|
|
if (errno != EINTR) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semop() failed releasing SYSVSEM_SETVAL for key 0x%x: %s", key, strerror(errno));
|
1999-04-22 10:48:28 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sem_ptr = (sysvsem_sem *) emalloc(sizeof(sysvsem_sem));
|
|
|
|
sem_ptr->key = key;
|
|
|
|
sem_ptr->semid = semid;
|
|
|
|
sem_ptr->count = 0;
|
2002-05-17 20:33:49 +08:00
|
|
|
sem_ptr->auto_release = auto_release;
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2002-09-27 18:24:54 +08:00
|
|
|
sem_ptr->id = ZEND_REGISTER_RESOURCE(return_value, sem_ptr, php_sysvsem_module.le_sem);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ php_sysvsem_semop
|
|
|
|
*/
|
1999-12-18 12:01:20 +08:00
|
|
|
static void php_sysvsem_semop(INTERNAL_FUNCTION_PARAMETERS, int acquire)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
1999-09-25 03:15:17 +08:00
|
|
|
pval **arg_id;
|
1999-04-22 10:48:28 +08:00
|
|
|
sysvsem_sem *sem_ptr;
|
|
|
|
struct sembuf sop;
|
|
|
|
|
2000-06-06 03:47:54 +08:00
|
|
|
switch(ZEND_NUM_ARGS()) {
|
1999-04-22 10:48:28 +08:00
|
|
|
case 1:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(1, &arg_id)==FAILURE) {
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-09-27 18:24:54 +08:00
|
|
|
ZEND_FETCH_RESOURCE(sem_ptr, sysvsem_sem *, arg_id, -1, "SysV semphore", php_sysvsem_module.le_sem);
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
if (!acquire && sem_ptr->count == 0) {
|
2002-09-27 18:24:54 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SysV semaphore %d (key 0x%x) is not currently acquired", Z_LVAL_PP(arg_id), sem_ptr->key);
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sop.sem_num = SYSVSEM_SEM;
|
|
|
|
sop.sem_op = acquire ? -1 : 1;
|
|
|
|
sop.sem_flg = SEM_UNDO;
|
|
|
|
|
|
|
|
while (semop(sem_ptr->semid, &sop, 1) == -1) {
|
|
|
|
if (errno != EINTR) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "semop(%s) failed for key 0x%x: %s",
|
1999-04-22 10:48:28 +08:00
|
|
|
acquire ? "acquire" : "release", sem_ptr->key, strerror(errno));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sem_ptr->count -= acquire ? -1 : 1;
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
|
|
|
/* {{{ proto int sem_acquire(int id)
|
2000-02-24 22:43:53 +08:00
|
|
|
Acquires the semaphore with the given id, blocking if necessary */
|
1999-12-18 12:01:20 +08:00
|
|
|
PHP_FUNCTION(sem_acquire)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
1999-12-18 12:01:20 +08:00
|
|
|
php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int sem_release(int id)
|
2000-02-24 22:43:53 +08:00
|
|
|
Releases the semaphore with the given id */
|
1999-12-18 12:01:20 +08:00
|
|
|
PHP_FUNCTION(sem_release)
|
1999-04-22 10:48:28 +08:00
|
|
|
{
|
1999-12-18 12:01:20 +08:00
|
|
|
php_sysvsem_semop(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-05-15 15:29:31 +08:00
|
|
|
/* {{{ proto int sem_remove(int id)
|
|
|
|
Removes semaphore from Unix systems */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* contributed by Gavin Sherry gavin@linuxworld.com.au
|
|
|
|
* Fri Mar 16 00:50:13 EST 2001
|
|
|
|
*/
|
|
|
|
|
|
|
|
PHP_FUNCTION(sem_remove)
|
|
|
|
{
|
2002-05-17 20:33:49 +08:00
|
|
|
pval **arg_id;
|
2001-05-15 15:29:31 +08:00
|
|
|
sysvsem_sem *sem_ptr;
|
|
|
|
#if HAVE_SEMUN
|
|
|
|
union semun un;
|
2002-05-17 20:33:49 +08:00
|
|
|
struct semid_ds buf;
|
2001-05-15 15:29:31 +08:00
|
|
|
#endif
|
|
|
|
|
2002-05-17 20:33:49 +08:00
|
|
|
if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_id) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-05-15 15:29:31 +08:00
|
|
|
|
2002-09-27 18:24:54 +08:00
|
|
|
ZEND_FETCH_RESOURCE(sem_ptr, sysvsem_sem *, arg_id, -1, "SysV semphore", php_sysvsem_module.le_sem);
|
2001-05-15 15:29:31 +08:00
|
|
|
|
|
|
|
#if HAVE_SEMUN
|
2002-05-17 20:33:49 +08:00
|
|
|
un.buf = &buf;
|
2002-09-27 18:24:54 +08:00
|
|
|
if(semctl(sem_ptr->semid, 0, IPC_STAT, un) < 0) {
|
2001-05-15 15:29:31 +08:00
|
|
|
#else
|
2002-05-17 20:33:49 +08:00
|
|
|
if(semctl(sem_ptr->semid, 0, IPC_STAT, NULL) < 0) {
|
2001-05-15 15:29:31 +08:00
|
|
|
#endif
|
2002-09-27 18:24:54 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SysV semphore %d does not (any longer) exist", Z_LVAL_PP(arg_id));
|
2002-05-17 20:33:49 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-05-15 15:29:31 +08:00
|
|
|
|
2002-03-28 15:36:02 +08:00
|
|
|
#if HAVE_SEMUN
|
2002-09-27 18:24:54 +08:00
|
|
|
if(semctl(sem_ptr->semid, 0, IPC_RMID, un) < 0) {
|
2002-03-28 15:36:02 +08:00
|
|
|
#else
|
2002-05-17 20:33:49 +08:00
|
|
|
if(semctl(sem_ptr->semid, 0, IPC_RMID, NULL) < 0) {
|
2002-03-28 15:36:02 +08:00
|
|
|
#endif
|
2002-09-27 18:24:54 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed for SysV sempphore %d: %s", Z_LVAL_PP(arg_id), strerror(errno));
|
2002-05-17 20:33:49 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-05-15 15:29:31 +08:00
|
|
|
|
|
|
|
/* let release_sysvsem_sem know we have removed
|
|
|
|
* the semaphore to avoid issues with releasing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sem_ptr->count = -1;
|
2002-05-17 20:33:49 +08:00
|
|
|
RETURN_TRUE;
|
2001-05-15 15:29:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif /* HAVE_SYSVSEM */
|
2001-06-05 21:12:10 +08:00
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
1999-04-22 10:48:28 +08:00
|
|
|
*/
|