740
void mysqld_list_processes(Session *session, const char *user)
743
List<Item> field_list;
744
vector<thread_info> thread_infos;
746
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
747
field_list.push_back(new Item_empty_string("User",16));
748
field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN));
749
field_list.push_back(field=new Item_empty_string("db",NAME_CHAR_LEN));
750
field->maybe_null= true;
751
field_list.push_back(new Item_empty_string("Command",16));
752
field_list.push_back(new Item_return_int("Time",7, DRIZZLE_TYPE_LONG));
753
field_list.push_back(field=new Item_empty_string("State",30));
754
field->maybe_null= true;
755
field_list.push_back(field=new Item_empty_string("Info", PROCESS_LIST_WIDTH));
756
field->maybe_null= true;
757
if (session->client->sendFields(&field_list))
760
pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
761
if (!session->killed)
764
for(vector<Session*>::iterator it= getSessionList().begin(); it != getSessionList().end(); ++it)
767
const SecurityContext *tmp_sctx= &tmp->getSecurityContext();
768
internal::st_my_thread_var *mysys_var;
769
if (tmp->client->isConnected() && (not user || (not tmp_sctx->getUser().compare(user))))
772
if ((mysys_var= tmp->mysys_var))
773
pthread_mutex_lock(&mysys_var->mutex);
775
const string tmp_proc_info((tmp->killed == Session::KILL_CONNECTION) ? "Killed" : command_name[tmp->command].str);
777
const string tmp_state_info(tmp->client->isWriting()
779
: tmp->client->isReading()
780
? (tmp->command == COM_SLEEP
782
: "Reading from net")
783
: tmp->get_proc_info()
784
? tmp->get_proc_info()
785
: (tmp->mysys_var && tmp->mysys_var->current_cond)
789
pthread_mutex_unlock(&mysys_var->mutex);
791
const string tmp_query((tmp->process_list_info[0]) ? tmp->process_list_info : "");
792
thread_infos.push_back(thread_info(tmp->thread_id,
795
tmp_sctx->getUser().empty()
796
? string("unauthenticated user")
797
: tmp_sctx->getUser(),
806
pthread_mutex_unlock(&LOCK_thread_count);
807
time_t now= time(NULL);
808
for(vector<thread_info>::iterator iter= thread_infos.begin();
809
iter != thread_infos.end();
812
session->client->store((uint64_t) (*iter).thread_id);
813
session->client->store((*iter).user);
814
session->client->store((*iter).host);
815
session->client->store((*iter).db);
816
session->client->store((*iter).proc_info);
818
if ((*iter).start_time)
819
session->client->store((uint32_t) (now - (*iter).start_time));
821
session->client->store();
823
session->client->store((*iter).state_info);
824
session->client->store((*iter).query);
826
if (session->client->flush())
834
740
/*****************************************************************************
836
742
*****************************************************************************/
838
static vector<SHOW_VAR *> all_status_vars;
744
static vector<drizzle_show_var *> all_status_vars;
839
745
static bool status_vars_inited= 0;
840
746
static int show_var_cmp(const void *var1, const void *var2)
842
return strcmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name);
748
return strcmp(((drizzle_show_var*)var1)->name, ((drizzle_show_var*)var2)->name);
845
751
class show_var_cmp_functor
848
754
show_var_cmp_functor() { }
849
inline bool operator()(const SHOW_VAR *var1, const SHOW_VAR *var2) const
755
inline bool operator()(const drizzle_show_var *var1, const drizzle_show_var *var2) const
851
757
int val= strcmp(var1->name, var2->name);
852
758
return (val < 0);
859
765
show_var_remove_if() { }
860
inline bool operator()(const SHOW_VAR *curr) const
766
inline bool operator()(const drizzle_show_var *curr) const
862
768
return (curr->type == SHOW_UNDEF);
866
SHOW_VAR *getFrontOfStatusVars()
772
drizzle_show_var *getFrontOfStatusVars()
868
774
return all_status_vars.front();
871
SHOW_VAR *getCommandStatusVars()
777
drizzle_show_var *getCommandStatusVars()
873
SHOW_VAR *tmp= all_status_vars.front();
779
drizzle_show_var *tmp= all_status_vars.front();
875
781
for (; tmp->name; tmp++)
877
783
if (tmp->type == SHOW_ARRAY)
878
return (SHOW_VAR *) tmp->value;
784
return (drizzle_show_var *) tmp->value;
885
Adds an array of SHOW_VAR entries to the output of SHOW STATUS
791
Adds an array of drizzle_show_var entries to the output of SHOW STATUS
888
add_status_vars(SHOW_VAR *list)
889
list - an array of SHOW_VAR entries to add to all_status_vars
794
add_status_vars(drizzle_show_var *list)
795
list - an array of drizzle_show_var entries to add to all_status_vars
890
796
the last entry must be {0,0,SHOW_UNDEF}