diff options
author | unknown <sasha@mysql.sashanet.com> | 2001-10-12 09:37:25 -0600 |
---|---|---|
committer | unknown <sasha@mysql.sashanet.com> | 2001-10-12 09:37:25 -0600 |
commit | a6c58676835f9424a5167a522497f1a20a5f03ee (patch) | |
tree | d203061bcdc7881db97565091caac83f2ac56fd4 /tools | |
parent | d34950e8d2db7a28c92c5129edc63a11bba0792d (diff) | |
download | mariadb-git-a6c58676835f9424a5167a522497f1a20a5f03ee.tar.gz |
changed manager to use my_net_*
fixed bug in master - unregister slaves when they disconnect
client/mysqlmanagerc.c:
changed default port
include/mysql.h:
use my_net_*
libmysql/manager.c:
use my_net_*
mysql-test/mysql-test-run.sh:
added support for client strace
sql/sql_parse.cc:
unregister slaves on disconnect
sql/sql_repl.cc:
unregister slaves on disconnect
sql/sql_repl.h:
unregister slaves on disconnect
tools/mysqlmanager.c:
changed to use my_net_*
Diffstat (limited to 'tools')
-rw-r--r-- | tools/mysqlmanager.c | 148 |
1 files changed, 59 insertions, 89 deletions
diff --git a/tools/mysqlmanager.c b/tools/mysqlmanager.c index 9cb04505e2f..e1743cd49ec 100644 --- a/tools/mysqlmanager.c +++ b/tools/mysqlmanager.c @@ -133,7 +133,7 @@ typedef enum {PARAM_STDOUT,PARAM_STDERR} PARAM_TYPE; struct manager_thd { - Vio* vio; + NET net; char user[MAX_USER_NAME+1]; int priv_flags; char* cmd_buf; @@ -154,7 +154,7 @@ struct manager_exec* cur_launch_exec=0; static struct manager_thd* manager_thd_new(Vio* vio); static struct manager_exec* manager_exec_new(char* arg_start,char* arg_end); -static void manager_exec_print(Vio* vio,struct manager_exec* e); +static void manager_exec_print(NET* net,struct manager_exec* e); static void manager_thd_free(struct manager_thd* thd); static void manager_exec_free(void* e); static void manager_exec_connect(struct manager_exec* e); @@ -291,9 +291,9 @@ static void die(const char* fmt,...); static void print_time(FILE* fp); static void clean_up(); static struct manager_cmd* lookup_cmd(char* s,int len); -static void client_msg(Vio* vio,int err_code,const char* fmt,...); -static void client_msg_pre(Vio* vio,int err_code,const char* fmt,...); -static void client_msg_raw(Vio* vio,int err_code,int pre,const char* fmt, +static void client_msg(NET* net,int err_code,const char* fmt,...); +static void client_msg_pre(NET* net,int err_code,const char* fmt,...); +static void client_msg_raw(NET* net,int err_code,int pre,const char* fmt, va_list args); static int authenticate(struct manager_thd* thd); static char* read_line(struct manager_thd* thd); /* returns pointer to end of @@ -371,7 +371,7 @@ static int exec_line(struct manager_thd* thd,char* buf,char* buf_end) *p=tolower(*p); if (!(cmd=lookup_cmd(buf,(int)(p-buf)))) { - client_msg(thd->vio,MANAGER_CLIENT_ERR, + client_msg(&thd->net,MANAGER_CLIENT_ERR, "Unrecognized command, type help to see list of supported\ commands"); return 1; @@ -393,13 +393,13 @@ static struct manager_cmd* lookup_cmd(char* s,int len) HANDLE_NOARG_DECL(handle_ping) { - client_msg(thd->vio,MANAGER_OK,"Server management daemon is alive"); + client_msg(&thd->net,MANAGER_OK,"Server management daemon is alive"); return 0; } HANDLE_NOARG_DECL(handle_quit) { - client_msg(thd->vio,MANAGER_OK,"Goodbye"); + client_msg(&thd->net,MANAGER_OK,"Goodbye"); thd->finished=1; return 0; } @@ -407,19 +407,19 @@ HANDLE_NOARG_DECL(handle_quit) HANDLE_NOARG_DECL(handle_help) { struct manager_cmd* cmd = commands; - Vio* vio = thd->vio; - client_msg_pre(vio,MANAGER_INFO,"Available commands:"); + NET* net = &thd->net; + client_msg_pre(net,MANAGER_INFO,"Available commands:"); for (;cmd->name;cmd++) { - client_msg_pre(vio,MANAGER_INFO,"%s - %s", cmd->name, cmd->help); + client_msg_pre(net,MANAGER_INFO,"%s - %s", cmd->name, cmd->help); } - client_msg_pre(vio,MANAGER_INFO,"End of help"); + client_msg_pre(net,MANAGER_INFO,"End of help"); return 0; } HANDLE_NOARG_DECL(handle_shutdown) { - client_msg(thd->vio,MANAGER_OK,"Shutdown started, goodbye"); + client_msg(&thd->net,MANAGER_OK,"Shutdown started, goodbye"); thd->finished=1; shutdown_requested = 1; if (!one_thread) @@ -470,10 +470,10 @@ HANDLE_DECL(handle_set_exec_con) } } pthread_mutex_unlock(&lock_exec_hash); - client_msg(thd->vio,MANAGER_OK,"Entry updated"); + client_msg(&thd->net,MANAGER_OK,"Entry updated"); return 0; err: - client_msg(thd->vio,MANAGER_CLIENT_ERR,error); + client_msg(&thd->net,MANAGER_CLIENT_ERR,error); return 1; } @@ -531,10 +531,10 @@ static int set_exec_param(struct manager_thd* thd, char* args_start, } strnmov(param,arg_p,FN_REFLEN); pthread_mutex_unlock(&lock_exec_hash); - client_msg(thd->vio,MANAGER_OK,"Entry updated"); + client_msg(&thd->net,MANAGER_OK,"Entry updated"); return 0; err: - client_msg(thd->vio,MANAGER_CLIENT_ERR,error); + client_msg(&thd->net,MANAGER_CLIENT_ERR,error); return 1; } @@ -581,10 +581,10 @@ HANDLE_DECL(handle_start_exec) pthread_mutex_unlock(&e->lock); if (error) goto err; - client_msg(thd->vio,MANAGER_OK,"'%s' started",e->ident); + client_msg(&thd->net,MANAGER_OK,"'%s' started",e->ident); return 0; err: - client_msg(thd->vio,MANAGER_CLIENT_ERR,error); + client_msg(&thd->net,MANAGER_CLIENT_ERR,error); return 1; } @@ -636,11 +636,11 @@ HANDLE_DECL(handle_stop_exec) pthread_mutex_unlock(&e->lock); if (!error) { - client_msg(thd->vio,MANAGER_OK,"'%s' terminated",e->ident); + client_msg(&thd->net,MANAGER_OK,"'%s' terminated",e->ident); return 0; } err: - client_msg(thd->vio,MANAGER_CLIENT_ERR,error); + client_msg(&thd->net,MANAGER_CLIENT_ERR,error); return 1; } @@ -705,7 +705,7 @@ HANDLE_DECL(handle_query) *p++='\t'; } *p=0; - client_msg_pre(thd->vio,MANAGER_OK,buf); + client_msg_pre(&thd->net,MANAGER_OK,buf); while ((row=mysql_fetch_row(res))) { @@ -716,14 +716,14 @@ HANDLE_DECL(handle_query) *p++='\t'; } *p=0; - client_msg_pre(thd->vio,MANAGER_OK,buf); + client_msg_pre(&thd->net,MANAGER_OK,buf); } } pthread_mutex_unlock(&e->lock); - client_msg(thd->vio,MANAGER_OK,"End"); + client_msg(&thd->net,MANAGER_OK,"End"); return 0; err: - client_msg(thd->vio,MANAGER_CLIENT_ERR,error); + client_msg(&thd->net,MANAGER_CLIENT_ERR,error); return 1; } @@ -756,10 +756,10 @@ HANDLE_DECL(handle_def_exec) } hash_insert(&exec_hash,(byte*)e); pthread_mutex_unlock(&lock_exec_hash); - client_msg(thd->vio,MANAGER_OK,"Exec definition created"); + client_msg(&thd->net,MANAGER_OK,"Exec definition created"); return 0; err: - client_msg(thd->vio,MANAGER_CLIENT_ERR,error); + client_msg(&thd->net,MANAGER_CLIENT_ERR,error); if (e) manager_exec_free(e); return 1; @@ -768,16 +768,16 @@ err: HANDLE_NOARG_DECL(handle_show_exec) { uint i; - client_msg_pre(thd->vio,MANAGER_INFO,"Exec_def\tPid\tExit_status\tCon_info\ + client_msg_pre(&thd->net,MANAGER_INFO,"Exec_def\tPid\tExit_status\tCon_info\ \tStdout\tStderr\tArguments"); pthread_mutex_lock(&lock_exec_hash); for (i=0;i<exec_hash.records;i++) { struct manager_exec* e=(struct manager_exec*)hash_element(&exec_hash,i); - manager_exec_print(thd->vio,e); + manager_exec_print(&thd->net,e); } pthread_mutex_unlock(&lock_exec_hash); - client_msg(thd->vio,MANAGER_INFO,"End"); + client_msg(&thd->net,MANAGER_INFO,"End"); return 0; } @@ -873,7 +873,7 @@ static char* arg_strmov(char* dest, const char* src, int n) return dest; } -static void manager_exec_print(Vio* vio,struct manager_exec* e) +static void manager_exec_print(NET* net,struct manager_exec* e) { char buf[MAX_MYSQL_MANAGER_MSG]; char* p=buf,*buf_end=buf+sizeof(buf)-1; @@ -921,7 +921,7 @@ static void manager_exec_print(Vio* vio,struct manager_exec* e) } end: *p=0; - client_msg_pre(vio,MANAGER_INFO,buf); + client_msg_pre(net,MANAGER_INFO,buf); return; } @@ -933,7 +933,7 @@ static int authenticate(struct manager_thd* thd) struct manager_user* u; char c; - client_msg(thd->vio,MANAGER_INFO, manager_greeting); + client_msg(&thd->net,MANAGER_INFO, manager_greeting); if (!(buf_end=read_line(thd))) return -1; for (buf=thd->cmd_buf,p=thd->user,p_end=p+MAX_USER_NAME; @@ -959,7 +959,7 @@ static int authenticate(struct manager_thd* thd) my_MD5Final(digest,&context); if (memcmp(u->md5_pass,digest,MD5_LEN)) return 1; - client_msg(thd->vio,MANAGER_OK,"OK"); + client_msg(&thd->net,MANAGER_OK,"OK"); return 0; } @@ -1121,7 +1121,7 @@ static pthread_handler_decl(process_connection,arg) return 0; /* Don't get cc warning */ } -static void client_msg_raw(Vio* vio, int err_code, int pre, const char* fmt, +static void client_msg_raw(NET* net, int err_code, int pre, const char* fmt, va_list args) { char buf[MAX_CLIENT_MSG_LEN],*p,*buf_end; @@ -1136,73 +1136,44 @@ static void client_msg_raw(Vio* vio, int err_code, int pre, const char* fmt, p=buf_end - 2; *p++='\r'; *p++='\n'; - if (vio_write(vio,buf,(uint)(p-buf))<=0) - log_err("Failed writing to client: errno=%d",errno); + if (my_net_write(net,buf,(uint)(p-buf)) || net_flush(net)) + log_err("Failed writing to client: errno=%d",net->last_errno); } -static void client_msg(Vio* vio, int err_code, const char* fmt, ...) +static void client_msg(NET* net, int err_code, const char* fmt, ...) { va_list args; va_start(args,fmt); - client_msg_raw(vio,err_code,0,fmt,args); + client_msg_raw(net,err_code,0,fmt,args); } -static void client_msg_pre(Vio* vio, int err_code, const char* fmt, ...) +static void client_msg_pre(NET* net, int err_code, const char* fmt, ...) { va_list args; va_start(args,fmt); - client_msg_raw(vio,err_code,1,fmt,args); + client_msg_raw(net,err_code,1,fmt,args); } static char* read_line(struct manager_thd* thd) { - char* p=thd->cmd_buf; - char* buf_end = thd->cmd_buf + manager_max_cmd_len; - int escaped = 0; - for (;p<buf_end;) - { - int len,read_len; - char *block_end,*p_back; - uint retry_count=0; - - read_len = min(NET_BLOCK,(uint)(buf_end-p)); - while ((len=vio_read(thd->vio,p,read_len))<=0) + uint len; + char* p, *buf_end; + if ((len=my_net_read(&thd->net)) == packet_error) { - if (vio_should_retry(thd->vio) && retry_count++ < MAX_RETRY_COUNT) - continue; log_err("Error reading command from client (Error: %d)", - vio_errno(thd->vio)); + errno); thd->fatal=1; return 0; } - block_end=p+len; - /* a trick to unescape in place */ - for (p_back=p;p<block_end;p++) + buf_end=thd->cmd_buf+len; + for (p=thd->cmd_buf;p<buf_end;p++) + if (*p == '\r' || *p == '\n') { - char c=*p; - if (c==ESCAPE_CHAR) - { - if (!escaped) - { - escaped=1; - continue; - } - else - escaped=0; - } - if (c==EOL_CHAR && !escaped) - break; - *p_back++=c; - escaped=0; - } - if (p!=block_end) - { - *p_back=0; - return p_back; + *p=0; + break; } - } - client_msg(thd->vio,MANAGER_CLIENT_ERR,"Command line too long"); - return 0; + + return p; } static void handle_child(int __attribute__((unused)) sig) @@ -1225,25 +1196,23 @@ static void handle_child(int __attribute__((unused)) sig) struct manager_thd* manager_thd_new(Vio* vio) { struct manager_thd* tmp; - if (!(tmp=(struct manager_thd*)my_malloc(sizeof(*tmp)+manager_max_cmd_len, + if (!(tmp=(struct manager_thd*)my_malloc(sizeof(*tmp), MYF(0)))) { log_err("Out of memory in manager_thd_new"); return 0; } - tmp->vio=vio; + my_net_init(&tmp->net,vio); tmp->user[0]=0; tmp->priv_flags=0; tmp->fatal=tmp->finished=0; - tmp->cmd_buf=(char*)tmp+sizeof(*tmp); + tmp->cmd_buf=tmp->net.read_pos; return tmp; } static void manager_thd_free(struct manager_thd* thd) { - if (thd->vio) - vio_close(thd->vio); - my_free((byte*)thd->vio,MYF(0)); + net_end(&thd->net); } static void clean_up() @@ -1413,7 +1382,7 @@ static int run_server_loop() if (authenticate(thd)) { - client_msg(vio,MANAGER_ACCESS, "Access denied"); + client_msg(&thd->net,MANAGER_ACCESS, "Access denied"); manager_thd_free(thd); continue; } @@ -1427,7 +1396,8 @@ static int run_server_loop() } else if (pthread_create(&th,&thr_attr,process_connection,(void*)thd)) { - client_msg(vio,MANAGER_INTERNAL_ERR,"Could not create thread, errno=%d", + client_msg(&thd->net,MANAGER_INTERNAL_ERR, + "Could not create thread, errno=%d", errno); manager_thd_free(thd); continue; |