summaryrefslogtreecommitdiff
path: root/ext/pcntl
diff options
context:
space:
mode:
authorArnaud Le Blanc <lbarnaud@php.net>2008-11-10 05:57:18 +0000
committerArnaud Le Blanc <lbarnaud@php.net>2008-11-10 05:57:18 +0000
commitcf7ad21ce55f98c53212b068f0f4c79111fb639c (patch)
tree111599812dd41b16dd7a581fdbf459741a49a3e9 /ext/pcntl
parent42325f9d4825c197a67fdb10c2c3e39ad19581fd (diff)
downloadphp-git-cf7ad21ce55f98c53212b068f0f4c79111fb639c.tar.gz
MFH: Added the oldset parameter to pcntl_sigprocmask().
Already documented.
Diffstat (limited to 'ext/pcntl')
-rwxr-xr-xext/pcntl/pcntl.c30
-rw-r--r--ext/pcntl/php_signal.h7
-rw-r--r--ext/pcntl/tests/002.phpt7
3 files changed, 38 insertions, 6 deletions
diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c
index 6b66780fa9..4270b73368 100755
--- a/ext/pcntl/pcntl.c
+++ b/ext/pcntl/pcntl.c
@@ -76,6 +76,7 @@ static
ZEND_BEGIN_ARG_INFO_EX(arginfo_pcntl_sigprocmask, 0, 0, 2)
ZEND_ARG_INFO(0, how)
ZEND_ARG_INFO(0, set)
+ ZEND_ARG_INFO(1, oldset)
ZEND_END_ARG_INFO()
static
@@ -760,20 +761,20 @@ PHP_FUNCTION(pcntl_signal_dispatch)
/* }}} */
#ifdef HAVE_SIGPROCMASK
-/* {{{ proto bool pcntl_sigprocmask(int how, array set)
+/* {{{ proto bool pcntl_sigprocmask(int how, array set[, array &oldset])
Examine and change blocked signals */
PHP_FUNCTION(pcntl_sigprocmask)
{
long how, signo;
- zval *user_set, **user_signo;
- sigset_t set;
+ zval *user_set, *user_oldset = NULL, **user_signo;
+ sigset_t set, oldset;
HashPosition pos;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", &how, &user_set) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la|z", &how, &user_set, &user_oldset) == FAILURE) {
return;
}
- if (sigemptyset(&set) != 0) {
+ if (sigemptyset(&set) != 0 || sigemptyset(&oldset) != 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
RETURN_FALSE;
}
@@ -793,11 +794,26 @@ PHP_FUNCTION(pcntl_sigprocmask)
zend_hash_move_forward_ex(Z_ARRVAL_P(user_set), &pos);
}
- if (sigprocmask(how, &set, NULL) != 0) {
+ if (sigprocmask(how, &set, &oldset) != 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
RETURN_FALSE;
}
+ if (user_oldset != NULL) {
+ if (Z_TYPE_P(user_oldset) != IS_ARRAY) {
+ zval_dtor(user_oldset);
+ array_init(user_oldset);
+ } else {
+ zend_hash_clean(Z_ARRVAL_P(user_oldset));
+ }
+ for (signo = 1; signo < MAX(NSIG-1, SIGRTMAX); ++signo) {
+ if (sigismember(&oldset, signo) != 1) {
+ continue;
+ }
+ add_next_index_long(user_oldset, signo);
+ }
+ }
+
RETURN_TRUE;
}
/* }}} */
@@ -859,6 +875,8 @@ static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{
if (Z_TYPE_P(user_siginfo) != IS_ARRAY) {
zval_dtor(user_siginfo);
array_init(user_siginfo);
+ } else {
+ zend_hash_clean(Z_ARRVAL_P(user_siginfo));
}
add_assoc_long_ex(user_siginfo, "signo", sizeof("signo"), siginfo.si_signo);
add_assoc_long_ex(user_siginfo, "errno", sizeof("errno"), siginfo.si_errno);
diff --git a/ext/pcntl/php_signal.h b/ext/pcntl/php_signal.h
index ed2e769dd7..cd1d547790 100644
--- a/ext/pcntl/php_signal.h
+++ b/ext/pcntl/php_signal.h
@@ -22,6 +22,13 @@
#ifndef PHP_SIGNAL_H
#define PHP_SIGNAL_H
+#ifndef NSIG
+# define NSIG 32
+#endif
+#ifndef SIGRTMAX
+# define SIGRTMAX 64
+#endif
+
typedef void Sigfunc(int);
Sigfunc *php_signal(int signo, Sigfunc *func, int restart);
diff --git a/ext/pcntl/tests/002.phpt b/ext/pcntl/tests/002.phpt
index 5fc1724daa..ac0ca9f75a 100644
--- a/ext/pcntl/tests/002.phpt
+++ b/ext/pcntl/tests/002.phpt
@@ -14,6 +14,11 @@ if ($pid == -1) {
die('failed');
} else if ($pid) {
pcntl_sigprocmask(SIG_BLOCK, array(SIGCHLD,(string)SIGTERM));
+ $oldset = array();
+ pcntl_sigprocmask(SIG_BLOCK, array(), $oldset);
+ var_dump(in_array(SIGCHLD, $oldset));
+ var_dump(in_array(SIGTERM, $oldset));
+
posix_kill(posix_getpid(), SIGTERM);
$signo = pcntl_sigwaitinfo(array(SIGTERM), $siginfo);
echo "signo == SIGTERM\n";
@@ -68,6 +73,8 @@ if ($pid == -1) {
?>
--EXPECTF--
+bool(true)
+bool(true)
signo == SIGTERM
bool(true)
code === SI_USER || SI_NOINFO