diff --git a/ext/pcntl/pcntl.c b/ext/pcntl/pcntl.c index e3b4a9c4c69f..de8d7dfecfd7 100644 --- a/ext/pcntl/pcntl.c +++ b/ext/pcntl/pcntl.c @@ -798,15 +798,16 @@ PHP_FUNCTION(pcntl_signal) RETURN_THROWS(); } - /* Add the function name to our signal table */ - handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle); - Z_TRY_ADDREF_P(handle); - + /* Register with the OS first so that on failure we don't record a handler that was never installed */ if (php_signal4(signo, pcntl_signal_handler, (int) restart_syscalls, 1) == (void *)SIG_ERR) { PCNTL_G(last_error) = errno; php_error_docref(NULL, E_WARNING, "Error assigning signal"); RETURN_FALSE; } + + /* Add the function name to our signal table */ + handle = zend_hash_index_update(&PCNTL_G(php_signal_table), signo, handle); + Z_TRY_ADDREF_P(handle); RETURN_TRUE; } /* }}} */