@@ -2178,77 +2178,77 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
2178
2178
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
2179
2179
DBUG_VOID_RETURN;
2180
2180
2181
+ if (thd->killed )
2182
+ DBUG_VOID_RETURN;
2183
+
2181
2184
mysql_mutex_lock (&LOCK_thread_count); // For unlink from list
2182
- if (!thd->killed )
2185
+ I_List_iterator<THD> it (threads);
2186
+ THD *tmp;
2187
+ while ((tmp=it++))
2183
2188
{
2184
- I_List_iterator<THD> it (threads);
2185
- THD *tmp;
2186
- while ((tmp=it++))
2189
+ Security_context *tmp_sctx= tmp->security_ctx ;
2190
+ struct st_my_thread_var *mysys_var;
2191
+ if ((tmp->vio_ok () || tmp->system_thread ) &&
2192
+ (!user || (tmp_sctx->user && !strcmp (tmp_sctx->user , user))))
2187
2193
{
2188
- Security_context *tmp_sctx= tmp->security_ctx ;
2189
- struct st_my_thread_var *mysys_var;
2190
- if ((tmp->vio_ok () || tmp->system_thread ) &&
2191
- (!user || (tmp_sctx->user && !strcmp (tmp_sctx->user , user))))
2194
+ thread_info *thd_info= new thread_info;
2195
+
2196
+ thd_info->thread_id =tmp->thread_id ;
2197
+ thd_info->user = thd->strdup (tmp_sctx->user ? tmp_sctx->user :
2198
+ (tmp->system_thread ?
2199
+ " system user" : " unauthenticated user" ));
2200
+ if (tmp->peer_port && (tmp_sctx->host || tmp_sctx->ip ) &&
2201
+ thd->security_ctx ->host_or_ip [0 ])
2192
2202
{
2193
- thread_info *thd_info= new thread_info;
2194
-
2195
- thd_info->thread_id =tmp->thread_id ;
2196
- thd_info->user = thd->strdup (tmp_sctx->user ? tmp_sctx->user :
2197
- (tmp->system_thread ?
2198
- " system user" : " unauthenticated user" ));
2199
- if (tmp->peer_port && (tmp_sctx->host || tmp_sctx->ip ) &&
2200
- thd->security_ctx ->host_or_ip [0 ])
2201
- {
2202
- if ((thd_info->host = (char *) thd->alloc (LIST_PROCESS_HOST_LEN+1 )))
2203
- my_snprintf ((char *) thd_info->host , LIST_PROCESS_HOST_LEN,
2204
- " %s:%u" , tmp_sctx->host_or_ip , tmp->peer_port );
2205
- }
2206
- else
2207
- thd_info->host = thd->strdup (tmp_sctx->host_or_ip [0 ] ?
2208
- tmp_sctx->host_or_ip :
2209
- tmp_sctx->host ? tmp_sctx->host : " " );
2210
- thd_info->command =(int ) tmp->command ;
2211
- mysql_mutex_lock (&tmp->LOCK_thd_data );
2212
- if ((thd_info->db = tmp->db )) // Safe test
2213
- thd_info->db = thd->strdup (thd_info->db );
2214
- if ((mysys_var= tmp->mysys_var ))
2215
- mysql_mutex_lock (&mysys_var->mutex );
2216
- thd_info->proc_info = (char *) (tmp->killed >= KILL_QUERY ?
2217
- " Killed" : 0 );
2218
- thd_info->state_info = thread_state_info (tmp);
2219
- if (mysys_var)
2220
- mysql_mutex_unlock (&mysys_var->mutex );
2221
-
2222
- /* Lock THD mutex that protects its data when looking at it. */
2223
- if (tmp->query ())
2224
- {
2225
- uint length= min (max_query_length, tmp->query_length ());
2226
- char *q= thd->strmake (tmp->query (),length);
2227
- /* Safety: in case strmake failed, we set length to 0. */
2228
- thd_info->query_string =
2229
- CSET_STRING (q, q ? length : 0 , tmp->query_charset ());
2230
- }
2203
+ if ((thd_info->host = (char *) thd->alloc (LIST_PROCESS_HOST_LEN+1 )))
2204
+ my_snprintf ((char *) thd_info->host , LIST_PROCESS_HOST_LEN,
2205
+ " %s:%u" , tmp_sctx->host_or_ip , tmp->peer_port );
2206
+ }
2207
+ else
2208
+ thd_info->host = thd->strdup (tmp_sctx->host_or_ip [0 ] ?
2209
+ tmp_sctx->host_or_ip :
2210
+ tmp_sctx->host ? tmp_sctx->host : " " );
2211
+ thd_info->command =(int ) tmp->command ;
2212
+ mysql_mutex_lock (&tmp->LOCK_thd_data );
2213
+ if ((thd_info->db = tmp->db )) // Safe test
2214
+ thd_info->db = thd->strdup (thd_info->db );
2215
+ if ((mysys_var= tmp->mysys_var ))
2216
+ mysql_mutex_lock (&mysys_var->mutex );
2217
+ thd_info->proc_info = (char *) (tmp->killed >= KILL_QUERY ?
2218
+ " Killed" : 0 );
2219
+ thd_info->state_info = thread_state_info (tmp);
2220
+ if (mysys_var)
2221
+ mysql_mutex_unlock (&mysys_var->mutex );
2231
2222
2232
- /*
2233
- Progress report. We need to do this under a lock to ensure that all
2234
- is from the same stage.
2235
- */
2236
- if (tmp->progress .max_counter )
2237
- {
2238
- uint max_stage= max (tmp->progress .max_stage , 1 );
2239
- thd_info->progress = (((tmp->progress .stage / (double ) max_stage) +
2240
- ((tmp->progress .counter /
2241
- (double ) tmp->progress .max_counter ) /
2242
- (double ) max_stage)) *
2243
- 100.0 );
2244
- set_if_smaller (thd_info->progress , 100 );
2245
- }
2246
- else
2247
- thd_info->progress = 0.0 ;
2248
- thd_info->start_time = tmp->start_time ;
2249
- mysql_mutex_unlock (&tmp->LOCK_thd_data );
2250
- thread_infos.append (thd_info);
2223
+ /* Lock THD mutex that protects its data when looking at it. */
2224
+ if (tmp->query ())
2225
+ {
2226
+ uint length= min (max_query_length, tmp->query_length ());
2227
+ char *q= thd->strmake (tmp->query (),length);
2228
+ /* Safety: in case strmake failed, we set length to 0. */
2229
+ thd_info->query_string =
2230
+ CSET_STRING (q, q ? length : 0 , tmp->query_charset ());
2251
2231
}
2232
+
2233
+ /*
2234
+ Progress report. We need to do this under a lock to ensure that all
2235
+ is from the same stage.
2236
+ */
2237
+ if (tmp->progress .max_counter )
2238
+ {
2239
+ uint max_stage= max (tmp->progress .max_stage , 1 );
2240
+ thd_info->progress = (((tmp->progress .stage / (double ) max_stage) +
2241
+ ((tmp->progress .counter /
2242
+ (double ) tmp->progress .max_counter ) /
2243
+ (double ) max_stage)) *
2244
+ 100.0 );
2245
+ set_if_smaller (thd_info->progress , 100 );
2246
+ }
2247
+ else
2248
+ thd_info->progress = 0.0 ;
2249
+ thd_info->start_time = tmp->start_time ;
2250
+ mysql_mutex_unlock (&tmp->LOCK_thd_data );
2251
+ thread_infos.append (thd_info);
2252
2252
}
2253
2253
}
2254
2254
mysql_mutex_unlock (&LOCK_thread_count);
0 commit comments