From 76424299f8dd69990a7812474803fac9ec52b0b2 Mon Sep 17 00:00:00 2001 From: Ben Fuhrmannek Date: Sat, 14 Aug 2021 18:44:26 +0200 Subject: debug log to dup'd stderr / php is closing stderr during shutdown --- src/snuffleupagus.c | 11 +++++++++++ src/sp_utils.h | 9 +++++++++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index 7bf3649..1ac04d0 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}; 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 @@ PHP_GINIT_FUNCTION(snuffleupagus) { } PHP_MINIT_FUNCTION(snuffleupagus) { + sp_log_debug("(MINIT)"); REGISTER_INI_ENTRIES(); return SUCCESS; @@ -244,6 +253,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 081f786..b5a1691 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(...) \ sp_log_msgf("DEBUG", SP_LOG_DEBUG, SP_TYPE_LOG, __VA_ARGS__) +#endif + #else #define sp_log_debug(...) #endif -- cgit v1.3