| 11568 | |
| 11569 | extern "C" |
| 11570 | char *thd_get_error_context_description(THD *thd, char *buffer, |
| 11571 | unsigned int length, |
| 11572 | unsigned int max_query_len) |
| 11573 | { |
| 11574 | String str(buffer, length, &my_charset_latin1); |
| 11575 | const Security_context *sctx= &thd->main_security_ctx; |
| 11576 | char header[256]; |
| 11577 | size_t len; |
| 11578 | |
| 11579 | len= my_snprintf(header, sizeof(header), |
| 11580 | "MariaDB thread id %u, OS thread handle %lu, query id %llu", |
| 11581 | (uint)thd->thread_id, (ulong) thd->real_id, (ulonglong) thd->query_id); |
| 11582 | str.length(0); |
| 11583 | str.append(header, len); |
| 11584 | |
| 11585 | if (sctx->host) |
| 11586 | { |
| 11587 | str.append(' '); |
| 11588 | str.append(sctx->host, strlen(sctx->host)); |
| 11589 | } |
| 11590 | |
| 11591 | if (sctx->ip) |
| 11592 | { |
| 11593 | str.append(' '); |
| 11594 | str.append(sctx->ip, strlen(sctx->ip)); |
| 11595 | } |
| 11596 | |
| 11597 | if (sctx->user) |
| 11598 | { |
| 11599 | str.append(' '); |
| 11600 | str.append(sctx->user, strlen(sctx->user)); |
| 11601 | } |
| 11602 | |
| 11603 | /* Don't wait if LOCK_thd_data is used as this could cause a deadlock */ |
| 11604 | if (!mysql_mutex_trylock(&thd->LOCK_thd_data)) |
| 11605 | { |
| 11606 | if (const char *info= thread_state_info(thd)) |
| 11607 | { |
| 11608 | str.append(' '); |
| 11609 | str.append(info, strlen(info)); |
| 11610 | } |
| 11611 | |
| 11612 | if (thd->query()) |
| 11613 | { |
| 11614 | if (max_query_len < 1) |
| 11615 | len= thd->query_length(); |
| 11616 | else |
| 11617 | len= MY_MIN(thd->query_length(), max_query_len); |
| 11618 | str.append('\n'); |
| 11619 | str.append(thd->query(), len); |
| 11620 | } |
| 11621 | mysql_mutex_unlock(&thd->LOCK_thd_data); |
| 11622 | } |
| 11623 | |
| 11624 | if (str.c_ptr_safe() == buffer) |
| 11625 | return buffer; |
| 11626 | |
| 11627 | /* |
no test coverage detected