From baecad40b5b8a977ce2a42f9ad1e31820254ae6e Mon Sep 17 00:00:00 2001 From: Ben Fuhrmannek Date: Fri, 6 Aug 2021 16:39:03 +0200 Subject: debug log to dup'd stderr / php is closing stderr during shutdown --- src/snuffleupagus.c | 17 +++++++++++++++++ src/sp_utils.h | 9 +++++++++ 2 files changed, 26 insertions(+) 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 @@ static PHP_INI_MH(OnUpdateConfiguration); static inline void sp_op_array_handler(zend_op_array *op); +#ifdef SP_DEBUG_STDERR +int sp_debug_stderr = STDERR_FILENO; +#endif + ZEND_EXTENSION(); // LCOV_EXCL_START @@ -70,6 +74,10 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = { STANDARD_ZEND_EXTENSION_PROPERTIES}; static PHP_GINIT_FUNCTION(snuffleupagus) { +#ifdef SP_DEBUG_STDERR + sp_debug_stderr = dup(STDERR_FILENO); +#endif + sp_log_debug("(GINIT)"); snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; snuffleupagus_globals->in_eval = 0; @@ -116,6 +124,7 @@ static PHP_GINIT_FUNCTION(snuffleupagus) { } PHP_MINIT_FUNCTION(snuffleupagus) { + sp_log_debug("(MINIT)"); REGISTER_INI_ENTRIES(); return SUCCESS; @@ -134,6 +143,7 @@ static inline void free_disabled_functions_hashtable(HashTable *const ht) { } static PHP_GSHUTDOWN_FUNCTION(snuffleupagus) { + sp_log_debug("(GSHUTDOWN)"); #define FREE_HT(F) \ zend_hash_destroy(snuffleupagus_globals->F); \ pefree(snuffleupagus_globals->F, 1); @@ -188,6 +198,11 @@ static PHP_GSHUTDOWN_FUNCTION(snuffleupagus) { FREE_CFG(config_disabled_functions_reg_ret); #undef FREE_CFG #undef FREE_CFG_ZSTR + +#ifdef SP_DEBUG_STDERR + close(sp_debug_stderr); + sp_debug_stderr = STDERR_FILENO; +#endif } PHP_RINIT_FUNCTION(snuffleupagus) { @@ -249,6 +264,8 @@ PHP_MINFO_FUNCTION(snuffleupagus) { } static PHP_INI_MH(OnUpdateConfiguration) { + sp_log_debug("(OnUpdateConfiguration)"); + TSRMLS_FETCH(); 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 @@ sp_log_msgf(feature, SP_LOG_ERROR, SP_TYPE_LOG, __VA_ARGS__) #define sp_log_warn(feature, ...) \ sp_log_msgf(feature, SP_LOG_WARN, SP_TYPE_LOG, __VA_ARGS__) + #ifdef SP_DEBUG + +#ifdef SP_DEBUG_STDERR +extern int sp_debug_stderr; +#define sp_log_debug(fmt, ...) \ + dprintf(sp_debug_stderr, "[snuffleupagus][DEBUG] %s(): " fmt "\n", __FUNCTION__, ##__VA_ARGS__); +#else #define sp_log_debug(fmt, ...) \ sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, "%s(): " fmt, __FUNCTION__, ##__VA_ARGS__) +#endif + #else #define sp_log_debug(...) #endif -- cgit v1.3