Skip to content

Commit

Permalink
Fix rust destructors for frankenphp
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <[email protected]>
  • Loading branch information
bwoebi committed Feb 29, 2024
1 parent 0841bd4 commit 60b8ded
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions ext/ddtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ static bool dd_has_other_observers;
static int dd_observer_extension_backup = -1;
#endif

datadog_php_sapi ddtrace_active_sapi;

_Atomic(int64_t) ddtrace_warn_legacy_api;

ZEND_DECLARE_MODULE_GLOBALS(ddtrace)
Expand Down Expand Up @@ -571,7 +573,7 @@ static PHP_GSHUTDOWN_FUNCTION(ddtrace) {
zai_hook_gshutdown();

#ifdef CXA_THREAD_ATEXIT_WRAPPER
if (!dd_is_main_thread) {
if (!dd_is_main_thread && ddtrace_active_sapi != DATADOG_PHP_SAPI_FRANKENPHP) {
dd_run_rust_thread_destructors(NULL);
}
#endif
Expand Down Expand Up @@ -983,8 +985,8 @@ static void dd_register_fatal_error_ce(void) {
ddtrace_ce_fatal_error = zend_register_internal_class_ex(&ce, zend_ce_exception);
}

static bool dd_is_compatible_sapi(datadog_php_string_view module_name) {
switch (datadog_php_sapi_from_name(module_name)) {
static bool dd_is_compatible_sapi() {
switch (ddtrace_active_sapi) {
case DATADOG_PHP_SAPI_APACHE2HANDLER:
case DATADOG_PHP_SAPI_CGI_FCGI:
case DATADOG_PHP_SAPI_CLI:
Expand All @@ -1000,8 +1002,7 @@ static bool dd_is_compatible_sapi(datadog_php_string_view module_name) {
}

static void dd_disable_if_incompatible_sapi_detected(void) {
datadog_php_string_view module_name = datadog_php_string_view_from_cstr(sapi_module.name);
if (UNEXPECTED(!dd_is_compatible_sapi(module_name))) {
if (UNEXPECTED(!dd_is_compatible_sapi())) {
LOG(WARN, "Incompatible SAPI detected '%s'; disabling ddtrace", sapi_module.name);
DDTRACE_G(disable) = 1;
}
Expand All @@ -1010,10 +1011,14 @@ static void dd_disable_if_incompatible_sapi_detected(void) {
static PHP_MINIT_FUNCTION(ddtrace) {
UNUSED(type);

ddtrace_active_sapi = datadog_php_sapi_from_name(datadog_php_string_view_from_cstr(sapi_module.name));

#ifdef CXA_THREAD_ATEXIT_WRAPPER
dd_is_main_thread = true;
glibc__cxa_thread_atexit_impl = CXA_THREAD_ATEXIT_PHP;
atexit(dd_clean_main_thread_locals);
if (ddtrace_active_sapi != DATADOG_PHP_SAPI_FRANKENPHP) {
dd_is_main_thread = true;
glibc__cxa_thread_atexit_impl = CXA_THREAD_ATEXIT_PHP;
atexit(dd_clean_main_thread_locals);
}
#endif

// Reset on every minit for `apachectl graceful`.
Expand Down

0 comments on commit 60b8ded

Please sign in to comment.