2011-06-03 05:16:50 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Zend Signal Handling |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 2008 The PHP Group |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available through the world-wide-web at the following url: |
|
|
|
|
| http://www.php.net/license/3_01.txt |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Lucas Nealan <lucas@php.net> |
|
|
|
|
| Arnaud Le Blanc <lbarnaud@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef ZEND_SIGNAL_H
|
|
|
|
#define ZEND_SIGNAL_H
|
|
|
|
|
2016-06-20 19:58:42 +08:00
|
|
|
#ifdef ZEND_SIGNALS
|
|
|
|
|
|
|
|
# ifdef HAVE_SIGNAL_H
|
|
|
|
# include <signal.h>
|
|
|
|
# endif
|
2011-06-03 05:16:50 +08:00
|
|
|
|
|
|
|
#ifndef NSIG
|
|
|
|
#define NSIG 65
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef ZEND_SIGNAL_QUEUE_SIZE
|
2015-09-01 23:51:40 +08:00
|
|
|
#define ZEND_SIGNAL_QUEUE_SIZE 64
|
2011-06-03 05:16:50 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Signal structs */
|
|
|
|
typedef struct _zend_signal_entry_t {
|
|
|
|
int flags; /* sigaction style flags */
|
|
|
|
void* handler; /* signal handler or context */
|
|
|
|
} zend_signal_entry_t;
|
|
|
|
|
|
|
|
typedef struct _zend_signal_t {
|
|
|
|
int signo;
|
|
|
|
siginfo_t *siginfo;
|
|
|
|
void* context;
|
|
|
|
} zend_signal_t;
|
|
|
|
|
|
|
|
typedef struct _zend_signal_queue_t {
|
|
|
|
zend_signal_t zend_signal;
|
|
|
|
struct _zend_signal_queue_t *next;
|
|
|
|
} zend_signal_queue_t;
|
|
|
|
|
|
|
|
/* Signal Globals */
|
|
|
|
typedef struct _zend_signal_globals_t {
|
|
|
|
int depth;
|
2015-03-05 18:11:22 +08:00
|
|
|
int blocked; /* 1==TRUE, 0==FALSE */
|
2011-06-03 05:16:50 +08:00
|
|
|
int running; /* in signal handler execution */
|
|
|
|
int active; /* internal signal handling is enabled */
|
|
|
|
zend_bool check; /* check for replaced handlers on shutdown */
|
|
|
|
zend_signal_entry_t handlers[NSIG];
|
|
|
|
zend_signal_queue_t pstorage[ZEND_SIGNAL_QUEUE_SIZE], *phead, *ptail, *pavail; /* pending queue */
|
|
|
|
} zend_signal_globals_t;
|
|
|
|
|
2016-06-20 19:58:42 +08:00
|
|
|
# ifdef ZTS
|
|
|
|
# define SIGG(v) ZEND_TSRMG(zend_signal_globals_id, zend_signal_globals_t *, v)
|
2011-06-03 05:16:50 +08:00
|
|
|
BEGIN_EXTERN_C()
|
|
|
|
ZEND_API extern int zend_signal_globals_id;
|
|
|
|
END_EXTERN_C()
|
2016-06-20 19:58:42 +08:00
|
|
|
# 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 */
|
|
|
|
|
|
|
|
# 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 */
|
|
|
|
|
|
|
|
ZEND_API void zend_signal_handler_unblock(void);
|
2014-12-14 06:06:14 +08:00
|
|
|
void zend_signal_activate(void);
|
|
|
|
void zend_signal_deactivate(void);
|
2017-03-09 15:42:32 +08:00
|
|
|
BEGIN_EXTERN_C()
|
2016-06-20 19:58:42 +08:00
|
|
|
void zend_signal_startup(void);
|
2017-03-09 15:42:32 +08:00
|
|
|
END_EXTERN_C()
|
2016-06-20 19:58:42 +08:00
|
|
|
void zend_signal_init(void);
|
|
|
|
|
2014-12-14 06:06:14 +08:00
|
|
|
ZEND_API int zend_signal(int signo, void (*handler)(int));
|
|
|
|
ZEND_API int zend_sigaction(int signo, const struct sigaction *act, struct sigaction *oldact);
|
2011-06-03 05:16:50 +08:00
|
|
|
|
2016-06-20 19:58:42 +08:00
|
|
|
#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(signo, handler) signal(signo, handler)
|
|
|
|
# define zend_sigaction(signo, act, oldact) sigaction(signo, act, oldact)
|
|
|
|
|
|
|
|
#endif /* ZEND_SIGNALS */
|
2011-06-03 05:16:50 +08:00
|
|
|
|
|
|
|
#endif /* ZEND_SIGNAL_H */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*/
|