diff --git a/Zend/zend.h b/Zend/zend.h index 23cf6ad8310..8fb2726dcf0 100644 --- a/Zend/zend.h +++ b/Zend/zend.h @@ -40,10 +40,7 @@ #include "zend_iterators.h" #include "zend_stream.h" #include "zend_smart_str_public.h" - -#ifdef ZEND_SIGNALS -# include "zend_signal.h" -#endif +#include "zend_signal.h" #ifndef ZEND_SIGNALS /* block/unblock interruptions callbacks might be used by SAPI, and were used @@ -52,7 +49,7 @@ # define HANDLE_BLOCK_INTERRUPTIONS() # define HANDLE_UNBLOCK_INTERRUPTIONS() #else -# define HANDLE_BLOCK_INTERRUPTIONS() ZEND_SIGNAL_BLOCK_INTERRUPUTIONS() +# define HANDLE_BLOCK_INTERRUPTIONS() ZEND_SIGNAL_BLOCK_INTERRUPTIONS() # define HANDLE_UNBLOCK_INTERRUPTIONS() ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() #endif diff --git a/Zend/zend_signal.c b/Zend/zend_signal.c index b4f57415d5e..40dcd3bb0d2 100644 --- a/Zend/zend_signal.c +++ b/Zend/zend_signal.c @@ -48,7 +48,19 @@ #ifdef ZTS ZEND_API int zend_signal_globals_id; #else -zend_signal_globals_t zend_signal_globals; +ZEND_API zend_signal_globals_t zend_signal_globals; +#endif /* not ZTS */ + +#define SIGNAL_BEGIN_CRITICAL() \ + sigset_t oldmask; \ + zend_sigprocmask(SIG_BLOCK, &global_sigmask, &oldmask); +#define SIGNAL_END_CRITICAL() \ + zend_sigprocmask(SIG_SETMASK, &oldmask, NULL); + +#ifdef ZTS +# define zend_sigprocmask(signo, set, oldset) tsrm_sigmask((signo), (set), (oldset)) +#else +# define zend_sigprocmask(signo, set, oldset) sigprocmask((signo), (set), (oldset)) #endif static void zend_signal_handler(int signo, siginfo_t *siginfo, void *context); @@ -338,7 +350,7 @@ static void zend_signal_globals_ctor(zend_signal_globals_t *zend_signal_globals) } /* }}} */ -void zend_signal_init() /* {{{ */ +void zend_signal_init(void) /* {{{ */ { int signo; struct sigaction sa = {{0}}; @@ -360,7 +372,7 @@ void zend_signal_init() /* {{{ */ /* {{{ zend_signal_startup * alloc zend signal globals */ -void zend_signal_startup() +void zend_signal_startup(void) { #ifdef ZTS diff --git a/Zend/zend_signal.h b/Zend/zend_signal.h index 0c32db52a38..f9662b8d946 100644 --- a/Zend/zend_signal.h +++ b/Zend/zend_signal.h @@ -23,9 +23,11 @@ #ifndef ZEND_SIGNAL_H #define ZEND_SIGNAL_H -#ifdef HAVE_SIGNAL_H -#include -#endif +#ifdef ZEND_SIGNALS + +# ifdef HAVE_SIGNAL_H +# include +# endif #ifndef NSIG #define NSIG 65 @@ -63,39 +65,51 @@ typedef struct _zend_signal_globals_t { zend_signal_queue_t pstorage[ZEND_SIGNAL_QUEUE_SIZE], *phead, *ptail, *pavail; /* pending queue */ } zend_signal_globals_t; -#ifdef ZTS -# define SIGG(v) ZEND_TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v) +# ifdef ZTS +# define SIGG(v) ZEND_TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v) BEGIN_EXTERN_C() ZEND_API extern int zend_signal_globals_id; END_EXTERN_C() -# define ZEND_SIGNAL_BLOCK_INTERRUPUTIONS() if (EXPECTED(zend_signal_globals_id)) { SIGG(depth)++; } -# define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (EXPECTED(zend_signal_globals_id) && UNEXPECTED(((SIGG(depth)--) == SIGG(blocked)))) { zend_signal_handler_unblock(); } -#else /* ZTS */ -# define SIGG(v) (zend_signal_globals.v) -extern ZEND_API zend_signal_globals_t zend_signal_globals; -# define ZEND_SIGNAL_BLOCK_INTERRUPUTIONS() SIGG(depth)++; -# define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (((SIGG(depth)--) == SIGG(blocked))) { zend_signal_handler_unblock(); } -#endif /* not ZTS */ +# else +# define SIGG(v) (zend_signal_globals.v) +BEGIN_EXTERN_C() +ZEND_API extern zend_signal_globals_t zend_signal_globals; +END_EXTERN_C() +# endif /* not ZTS */ -# define SIGNAL_BEGIN_CRITICAL() sigset_t oldmask; \ - zend_sigprocmask(SIG_BLOCK, &global_sigmask, &oldmask); -# define SIGNAL_END_CRITICAL() zend_sigprocmask(SIG_SETMASK, &oldmask, NULL); +# ifdef ZTS +# define ZEND_SIGNAL_BLOCK_INTERRUPTIONS() if (EXPECTED(zend_signal_globals_id)) { SIGG(depth)++; } +# define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (EXPECTED(zend_signal_globals_id) && UNEXPECTED(((SIGG(depth)--) == SIGG(blocked)))) { zend_signal_handler_unblock(); } +# else /* ZTS */ +# define ZEND_SIGNAL_BLOCK_INTERRUPTIONS() SIGG(depth)++; +# define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() if (((SIGG(depth)--) == SIGG(blocked))) { zend_signal_handler_unblock(); } +# endif /* not ZTS */ -void zend_signal_handler_defer(int signo, siginfo_t *siginfo, void *context); -ZEND_API void zend_signal_handler_unblock(); +ZEND_API void zend_signal_handler_unblock(void); void zend_signal_activate(void); void zend_signal_deactivate(void); -void zend_signal_startup(); -void zend_signal_init(); +void zend_signal_startup(void); +void zend_signal_init(void); void zend_signal_shutdown(void); + ZEND_API int zend_signal(int signo, void (*handler)(int)); ZEND_API int zend_sigaction(int signo, const struct sigaction *act, struct sigaction *oldact); -#ifdef ZTS -#define zend_sigprocmask(signo, set, oldset) tsrm_sigmask((signo), (set), (oldset)) -#else -#define zend_sigprocmask(signo, set, oldset) sigprocmask((signo), (set), (oldset)) -#endif +#else /* ZEND_SIGNALS */ + +# define ZEND_SIGNAL_BLOCK_INTERRUPTIONS() +# define ZEND_SIGNAL_UNBLOCK_INTERRUPTIONS() + +# define zend_signal_activate() +# define zend_signal_deactivate() +# define zend_signal_startup() +# define zend_signal_init() +# define zend_signal_shutdown() + +# define zend_signal(signo, handler) signal(signo, handler) +# define zend_sigaction(signo, act, oldact) sigaction(signo, act, oldact) + +#endif /* ZEND_SIGNALS */ #endif /* ZEND_SIGNAL_H */ diff --git a/ext/pcntl/php_signal.c b/ext/pcntl/php_signal.c index 7aa5d5a7c1e..a18e641d2a6 100644 --- a/ext/pcntl/php_signal.c +++ b/ext/pcntl/php_signal.c @@ -28,8 +28,7 @@ Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all) { struct sigaction act,oact; -#ifdef ZEND_SIGNALS -#endif + act.sa_handler = func; if (mask_all) { sigfillset(&act.sa_mask); @@ -46,12 +45,7 @@ Sigfunc *php_signal4(int signo, Sigfunc *func, int restart, int mask_all) act.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */ #endif } -#ifdef ZEND_SIGNALS - if (zend_sigaction(signo, &act, &oact) < 0) -#else - if (sigaction(signo, &act, &oact) < 0) -#endif - { + if (zend_sigaction(signo, &act, &oact) < 0) { return SIG_ERR; } diff --git a/main/main.c b/main/main.c index ad65483437d..00471e9c925 100644 --- a/main/main.c +++ b/main/main.c @@ -1597,9 +1597,7 @@ int php_request_startup(void) zend_activate(); sapi_activate(); -#ifdef ZEND_SIGNALS zend_signal_activate(); -#endif if (PG(max_input_time) == -1) { zend_set_timeout(EG(timeout_seconds), 1); diff --git a/sapi/apache2handler/sapi_apache2.c b/sapi/apache2handler/sapi_apache2.c index 456b9719fa4..6f6de422baa 100644 --- a/sapi/apache2handler/sapi_apache2.c +++ b/sapi/apache2handler/sapi_apache2.c @@ -456,9 +456,7 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp ZEND_TSRMLS_CACHE_UPDATE(); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif sapi_startup(&apache2_sapi_module); apache2_sapi_module.startup(&apache2_sapi_module); diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index e758b33eeb8..e3398e03e05 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1800,9 +1800,7 @@ int main(int argc, char *argv[]) ZEND_TSRMLS_CACHE_UPDATE(); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif #ifdef ZTS ts_allocate_id(&php_cgi_globals_id, sizeof(php_cgi_globals_struct), (ts_allocate_ctor) php_cgi_globals_ctor, NULL); diff --git a/sapi/cli/php_cli.c b/sapi/cli/php_cli.c index 09ce00f9e76..3c7a136f4ef 100644 --- a/sapi/cli/php_cli.c +++ b/sapi/cli/php_cli.c @@ -1230,9 +1230,7 @@ int main(int argc, char *argv[]) ZEND_TSRMLS_CACHE_UPDATE(); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif #ifdef PHP_WIN32 _fmode = _O_BINARY; /*sets default for file streams to binary */ diff --git a/sapi/embed/php_embed.c b/sapi/embed/php_embed.c index 18c20272715..7cc4e6a1263 100644 --- a/sapi/embed/php_embed.c +++ b/sapi/embed/php_embed.c @@ -177,9 +177,7 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv) ZEND_TSRMLS_CACHE_UPDATE(); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif sapi_startup(&php_embed_module); diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c index 5adeb63b7a1..6dc8343fe6a 100644 --- a/sapi/fpm/fpm/fpm_main.c +++ b/sapi/fpm/fpm/fpm_main.c @@ -1612,9 +1612,7 @@ int main(int argc, char *argv[]) tsrm_ls = ts_resource(0); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif sapi_startup(&cgi_sapi_module); cgi_sapi_module.php_ini_path_override = NULL; diff --git a/sapi/fpm/fpm/fpm_signals.c b/sapi/fpm/fpm/fpm_signals.c index a637e69e719..8d0a4caf255 100644 --- a/sapi/fpm/fpm/fpm_signals.c +++ b/sapi/fpm/fpm/fpm_signals.c @@ -242,9 +242,7 @@ int fpm_signals_init_child() /* {{{ */ return -1; } -#ifdef ZEND_SIGNALS zend_signal_init(); -#endif return 0; } /* }}} */ diff --git a/sapi/litespeed/lsapi_main.c b/sapi/litespeed/lsapi_main.c index 4dede3f7177..da7ca2c30c3 100644 --- a/sapi/litespeed/lsapi_main.c +++ b/sapi/litespeed/lsapi_main.c @@ -1007,9 +1007,7 @@ int main( int argc, char * argv[] ) tsrm_startup(1, 1, 0, NULL); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif if (argc > 1 ) { if ( parse_opt( argc, argv, &climode, diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c index 68a164c4992..e72b543a42e 100644 --- a/sapi/phpdbg/phpdbg.c +++ b/sapi/phpdbg/phpdbg.c @@ -1241,11 +1241,7 @@ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) /* {{{ */ } is_handled = phpdbg_watchpoint_segfault_handler(info, context); if (is_handled == FAILURE) { -#ifdef ZEND_SIGNALS zend_sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL); -#else - sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL); -#endif } break; } @@ -1342,9 +1338,7 @@ int main(int argc, char **argv) /* {{{ */ ZEND_TSRMLS_CACHE_UPDATE(); #endif -#ifdef ZEND_SIGNALS zend_signal_startup(); -#endif phpdbg_main: ini_entries = NULL;