void xdebug_log_stack(const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC) { xdebug_llist_element *le; function_stack_entry *i; char *tmp_log_message; tmp_log_message = xdebug_sprintf( "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); php_log_err(tmp_log_message TSRMLS_CC); xdfree(tmp_log_message); if (XG(stack) && XG(stack)->size) { php_log_err("PHP Stack trace:" TSRMLS_CC); for (le = XDEBUG_LLIST_HEAD(XG(stack)); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { int c = 0; /* Comma flag */ unsigned int j = 0; /* Counter */ char *tmp_name; xdebug_str log_buffer = {0, 0, NULL}; i = XDEBUG_LLIST_VALP(le); tmp_name = xdebug_show_fname(i->function, 0, 0 TSRMLS_CC); xdebug_str_add(&log_buffer, xdebug_sprintf("PHP %3d. %s(", i->level, tmp_name), 1); xdfree(tmp_name); /* Printing vars */ for (j = 0; j < i->varc; j++) { char *tmp_varname, *tmp_value; if (c) { xdebug_str_addl(&log_buffer, ", ", 2, 0); } else { c = 1; } tmp_varname = i->var[j].name ? xdebug_sprintf("$%s = ", i->var[j].name) : xdstrdup(""); xdebug_str_add(&log_buffer, tmp_varname, 0); xdfree(tmp_varname); if (i->var[j].addr) { tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL); xdebug_str_add(&log_buffer, tmp_value, 0); xdfree(tmp_value); } else { xdebug_str_addl(&log_buffer, "*uninitialized*", 15, 0); } } xdebug_str_add(&log_buffer, xdebug_sprintf(") %s:%d", i->filename, i->lineno), 1); php_log_err(log_buffer.d TSRMLS_CC); xdebug_str_free(&log_buffer); } } }
static uepc_status use_existing_persistent_connection(const char* hash_key, int hash_key_len, php_yrmcds_t** res, yrmcds_error* err, yrmcds_status* status) { zend_resource* le; if( (le = zend_hash_str_find_ptr(&EG(persistent_list), hash_key, hash_key_len)) == NULL ) return UEPC_NOT_FOUND; if( le->type != le_yrmcds ) return UEPC_NOT_FOUND; php_yrmcds_t* c = le->ptr; if( (zend_bool)YRMCDS_G(detect_stale_connection) ) { *err = check_persistent_connection(c, status); if( *err != YRMCDS_OK || *status != YRMCDS_STATUS_OK ) { size_t refcount = c->reference_count; on_broken_connection_detected(c, *err, *status); return refcount == 0 ? UEPC_BROKEN : UEPC_BROKEN_AND_OCCUPIED; } } c->reference_count += 1; if( c->reference_count > 1 ) php_log_err("yrmcds: clients share the same persistent connection."); *res = c; return UEPC_OK; }
static void on_broken_connection_detected(php_yrmcds_t* conn, yrmcds_error err, yrmcds_status status) { if( err != YRMCDS_OK ) PRINT_YRMCDS_ERROR(err); if( status != YRMCDS_STATUS_OK && status != YRMCDS_STATUS_UNKNOWNCOMMAND ) { char buf[256]; snprintf(buf, sizeof(buf), "yrmcds: unexpected response (%d)", status); php_log_err(buf); } php_log_err("yrmcds: broken persistent connection"); if( conn->reference_count == 0 ) { // Since `conn` is the last user of this persistent connection, // we should clean up resources. zend_hash_str_del(&EG(persistent_list), conn->pkey, conn->pkey_len); } }
// Formats the error message and writes to the php error log. void pdo_sqlsrv_log( unsigned int severity TSRMLS_DC, const char* msg, va_list* print_args ) { if( (severity & PDO_SQLSRV_G( log_severity )) == 0 ) { return; } DWORD rc = FormatMessage( FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, log_msg, LOG_MSG_SIZE, print_args ); // if an error occurs for FormatMessage, we just output an internal error occurred. if( rc == 0 ) { SQLSRV_STATIC_ASSERT( sizeof( INTERNAL_FORMAT_ERROR ) < sizeof( log_msg )); std::copy( INTERNAL_FORMAT_ERROR, INTERNAL_FORMAT_ERROR + sizeof( INTERNAL_FORMAT_ERROR ), log_msg ); } php_log_err( log_msg TSRMLS_CC ); }
static ZEND_RSRC_DTOR_FUNC(php_yrmcds_resource_pdtor) { if( res->ptr == NULL ) return; php_yrmcds_t* c = (php_yrmcds_t*)res->ptr; if( c->reference_count != 0 ) { char buf[256]; snprintf(buf, sizeof(buf), "yrmcds: non-zero reference_count on pdtor: %zu", c->reference_count); php_log_err(buf); } yrmcds_close(&c->res); pefree((void*)c->pkey, 1); pefree(c, 1); res->ptr = NULL; }