diff options
| author | Ben Fuhrmannek | 2021-08-06 16:39:03 +0200 |
|---|---|---|
| committer | Ben Fuhrmannek | 2021-08-06 16:39:03 +0200 |
| commit | baecad40b5b8a977ce2a42f9ad1e31820254ae6e (patch) | |
| tree | 149111f9704d32df38a3761f936be58201af041d | |
| parent | 62f6d31d88e4536269b60471d7a4f7431442276a (diff) | |
debug log to dup'd stderr / php is closing stderr during shutdown
| -rw-r--r-- | src/snuffleupagus.c | 17 | ||||
| -rw-r--r-- | src/sp_utils.h | 9 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index d8a86b5..8c7ecbf 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -13,6 +13,10 @@ | |||
| 13 | static PHP_INI_MH(OnUpdateConfiguration); | 13 | static PHP_INI_MH(OnUpdateConfiguration); |
| 14 | static inline void sp_op_array_handler(zend_op_array *op); | 14 | static inline void sp_op_array_handler(zend_op_array *op); |
| 15 | 15 | ||
| 16 | #ifdef SP_DEBUG_STDERR | ||
| 17 | int sp_debug_stderr = STDERR_FILENO; | ||
| 18 | #endif | ||
| 19 | |||
| 16 | ZEND_EXTENSION(); | 20 | ZEND_EXTENSION(); |
| 17 | 21 | ||
| 18 | // LCOV_EXCL_START | 22 | // LCOV_EXCL_START |
| @@ -70,6 +74,10 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = { | |||
| 70 | STANDARD_ZEND_EXTENSION_PROPERTIES}; | 74 | STANDARD_ZEND_EXTENSION_PROPERTIES}; |
| 71 | 75 | ||
| 72 | static PHP_GINIT_FUNCTION(snuffleupagus) { | 76 | static PHP_GINIT_FUNCTION(snuffleupagus) { |
| 77 | #ifdef SP_DEBUG_STDERR | ||
| 78 | sp_debug_stderr = dup(STDERR_FILENO); | ||
| 79 | #endif | ||
| 80 | sp_log_debug("(GINIT)"); | ||
| 73 | snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; | 81 | snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; |
| 74 | snuffleupagus_globals->in_eval = 0; | 82 | snuffleupagus_globals->in_eval = 0; |
| 75 | 83 | ||
| @@ -116,6 +124,7 @@ static PHP_GINIT_FUNCTION(snuffleupagus) { | |||
| 116 | } | 124 | } |
| 117 | 125 | ||
| 118 | PHP_MINIT_FUNCTION(snuffleupagus) { | 126 | PHP_MINIT_FUNCTION(snuffleupagus) { |
| 127 | sp_log_debug("(MINIT)"); | ||
| 119 | REGISTER_INI_ENTRIES(); | 128 | REGISTER_INI_ENTRIES(); |
| 120 | 129 | ||
| 121 | return SUCCESS; | 130 | return SUCCESS; |
| @@ -134,6 +143,7 @@ static inline void free_disabled_functions_hashtable(HashTable *const ht) { | |||
| 134 | } | 143 | } |
| 135 | 144 | ||
| 136 | static PHP_GSHUTDOWN_FUNCTION(snuffleupagus) { | 145 | static PHP_GSHUTDOWN_FUNCTION(snuffleupagus) { |
| 146 | sp_log_debug("(GSHUTDOWN)"); | ||
| 137 | #define FREE_HT(F) \ | 147 | #define FREE_HT(F) \ |
| 138 | zend_hash_destroy(snuffleupagus_globals->F); \ | 148 | zend_hash_destroy(snuffleupagus_globals->F); \ |
| 139 | pefree(snuffleupagus_globals->F, 1); | 149 | pefree(snuffleupagus_globals->F, 1); |
| @@ -188,6 +198,11 @@ static PHP_GSHUTDOWN_FUNCTION(snuffleupagus) { | |||
| 188 | FREE_CFG(config_disabled_functions_reg_ret); | 198 | FREE_CFG(config_disabled_functions_reg_ret); |
| 189 | #undef FREE_CFG | 199 | #undef FREE_CFG |
| 190 | #undef FREE_CFG_ZSTR | 200 | #undef FREE_CFG_ZSTR |
| 201 | |||
| 202 | #ifdef SP_DEBUG_STDERR | ||
| 203 | close(sp_debug_stderr); | ||
| 204 | sp_debug_stderr = STDERR_FILENO; | ||
| 205 | #endif | ||
| 191 | } | 206 | } |
| 192 | 207 | ||
| 193 | PHP_RINIT_FUNCTION(snuffleupagus) { | 208 | PHP_RINIT_FUNCTION(snuffleupagus) { |
| @@ -249,6 +264,8 @@ PHP_MINFO_FUNCTION(snuffleupagus) { | |||
| 249 | } | 264 | } |
| 250 | 265 | ||
| 251 | static PHP_INI_MH(OnUpdateConfiguration) { | 266 | static PHP_INI_MH(OnUpdateConfiguration) { |
| 267 | sp_log_debug("(OnUpdateConfiguration)"); | ||
| 268 | |||
| 252 | TSRMLS_FETCH(); | 269 | TSRMLS_FETCH(); |
| 253 | 270 | ||
| 254 | if (!new_value || !new_value->len) { | 271 | if (!new_value || !new_value->len) { |
diff --git a/src/sp_utils.h b/src/sp_utils.h index 7c287da..5537a34 100644 --- a/src/sp_utils.h +++ b/src/sp_utils.h | |||
| @@ -51,9 +51,18 @@ | |||
| 51 | sp_log_msgf(feature, SP_LOG_ERROR, SP_TYPE_LOG, __VA_ARGS__) | 51 | sp_log_msgf(feature, SP_LOG_ERROR, SP_TYPE_LOG, __VA_ARGS__) |
| 52 | #define sp_log_warn(feature, ...) \ | 52 | #define sp_log_warn(feature, ...) \ |
| 53 | sp_log_msgf(feature, SP_LOG_WARN, SP_TYPE_LOG, __VA_ARGS__) | 53 | sp_log_msgf(feature, SP_LOG_WARN, SP_TYPE_LOG, __VA_ARGS__) |
| 54 | |||
| 54 | #ifdef SP_DEBUG | 55 | #ifdef SP_DEBUG |
| 56 | |||
| 57 | #ifdef SP_DEBUG_STDERR | ||
| 58 | extern int sp_debug_stderr; | ||
| 59 | #define sp_log_debug(fmt, ...) \ | ||
| 60 | dprintf(sp_debug_stderr, "[snuffleupagus][DEBUG] %s(): " fmt "\n", __FUNCTION__, ##__VA_ARGS__); | ||
| 61 | #else | ||
| 55 | #define sp_log_debug(fmt, ...) \ | 62 | #define sp_log_debug(fmt, ...) \ |
| 56 | sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__) | 63 | sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__) |
| 64 | #endif | ||
| 65 | |||
| 57 | #else | 66 | #else |
| 58 | #define sp_log_debug(...) | 67 | #define sp_log_debug(...) |
| 59 | #endif | 68 | #endif |
