]> granicus.if.org Git - php/commitdiff
Added the oldset parameter to pcntl_sigprocmask().
authorArnaud Le Blanc <lbarnaud@php.net>
Mon, 10 Nov 2008 05:56:22 +0000 (05:56 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Mon, 10 Nov 2008 05:56:22 +0000 (05:56 +0000)
Already documented.

ext/pcntl/pcntl.c
ext/pcntl/php_signal.h
ext/pcntl/tests/002.phpt

index 6bc6241aa98c0ffdd4ed213ceffdc02a79a50e81..5ef93785661c9e556c3a9fbb3f6bbd115e0d730d 100755 (executable)
@@ -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_ascii_assoc_long_ex(user_siginfo, "signo", sizeof("signo"), siginfo.si_signo);
                add_ascii_assoc_long_ex(user_siginfo, "errno", sizeof("errno"), siginfo.si_errno);
index ed2e769dd77faf87cbce487330fc0526c0345863..cd1d547790ffc4dcab45e67507fb8307f105f022 100644 (file)
 #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);
 
index 5fc1724daac2ec065e877ddb2e9f61986d59b4d6..ac0ca9f75a4ddd7587f1d95a600d5dc49dc7a3d8 100644 (file)
@@ -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