summaryrefslogtreecommitdiff
path: root/ext/sysvsem
diff options
context:
space:
mode:
authorGavin Sherry <swm@php.net>2001-05-15 07:29:31 +0000
committerGavin Sherry <swm@php.net>2001-05-15 07:29:31 +0000
commit00f013189e804a39d644c1d8f55f38ef2144c86d (patch)
tree4c3253647bd110744dfa84698ee4d63c850545c6 /ext/sysvsem
parent613aacf0b0346552faf94d443e6bdd91ddc05f05 (diff)
downloadphp-git-00f013189e804a39d644c1d8f55f38ef2144c86d.tar.gz
Added sem_remove to remove semaphores from memory
Diffstat (limited to 'ext/sysvsem')
-rw-r--r--ext/sysvsem/sysvsem.c75
1 files changed, 72 insertions, 3 deletions
diff --git a/ext/sysvsem/sysvsem.c b/ext/sysvsem/sysvsem.c
index ac0bf5d46b..950c4e6bcc 100644
--- a/ext/sysvsem/sysvsem.c
+++ b/ext/sysvsem/sysvsem.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP version 4.0 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2001 The PHP Group |
+ | Copyright (c) 1997-2001 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 2.02 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -12,13 +12,16 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Authors: Tom May <tom@go2net.com> |
+ | Authors: Tom May <tom@go2net.com> |
+ | Gavin Sherry <gavin@linuxworld.com.au> |
+----------------------------------------------------------------------+
*/
/* $Id$ */
-/* This has been built and tested on Solaris 2.6 and Linux 2.1.122.
+/* 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.
* It may not compile or execute correctly on other systems.
*
* sas: Works for me on Linux 2.0.36 and FreeBSD 3.0-current
@@ -53,6 +56,7 @@ function_entry sysvsem_functions[] = {
PHP_FE(sem_get, NULL)
PHP_FE(sem_acquire, NULL)
PHP_FE(sem_release, NULL)
+ PHP_FE(sem_remove, NULL)
{NULL, NULL, NULL}
};
@@ -92,6 +96,14 @@ static void release_sysvsem_sem(zend_rsrc_list_entry *rsrc)
sysvsem_sem *sem_ptr = (sysvsem_sem *)rsrc->ptr;
struct sembuf sop[2];
+/*
+ * if count == -1, semaphore has been removed
+ * Need better way to handle this
+ */
+
+ if(sem_ptr->count == -1) {
+ return;
+ }
/* Decrement the usage count. */
sop[0].sem_num = SYSVSEM_USAGE;
@@ -345,6 +357,63 @@ PHP_FUNCTION(sem_release)
}
/* }}} */
+
+
+
+/* {{{ 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)
+{
+ pval **arg_id;
+ int id,type;
+ sysvsem_sem *sem_ptr;
+#if HAVE_SEMUN
+ union semun un;
+#endif
+ if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_id) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_long_ex(arg_id);
+
+ id = (*arg_id)->value.lval;
+
+ sem_ptr = (sysvsem_sem *) zend_list_find(id, &type);
+
+ if (type!=php_sysvsem_module.le_sem) {
+ php_error(E_WARNING, "%d is not a SysV semaphore index", id);
+ RETURN_FALSE;
+ }
+
+#if HAVE_SEMUN
+ if(semctl(sem_ptr->semid,NULL,IPC_STAT,un)<0) {
+#else
+ if(semctl(sem_ptr->semid,NULL,IPC_STAT,NULL)<0) {
+#endif
+ php_error(E_WARNING, "%d is not a existing SysV Semaphore Id", id);
+ RETURN_FALSE;
+ }
+
+ if(semctl(sem_ptr->semid,NULL,IPC_RMID,NULL)<0) {
+ php_error(E_WARNING, "sem_remove() failed for id %d: %s", id, strerror(errno));
+ RETURN_FALSE;
+ }
+
+ /* let release_sysvsem_sem know we have removed
+ * the semaphore to avoid issues with releasing.
+ */
+
+ sem_ptr->count = -1;
+ RETURN_TRUE;
+}
+
+/* }}} */
+
#endif /* HAVE_SYSVSEM */
/*
* Local variables: