Skip to content
Snippets Groups Projects
Commit 196afd3b authored by Eugine Blikh's avatar Eugine Blikh
Browse files

Add support for github ticket #90

parent 39cd14e6
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <connector/c/include/tarantool/tnt.h> #include <connector/c/include/tarantool/tnt.h>
#include <connector/c/include/tarantool/tnt_net.h> #include <connector/c/include/tarantool/tnt_net.h>
#include <connector/c/include/tarantool/tnt_sql.h> #include <connector/c/include/tarantool/tnt_sql.h>
#include <connector/c/include/tarantool/tnt_iter.h>
#include <connector/c/include/tarantool/tnt_xlog.h> #include <connector/c/include/tarantool/tnt_xlog.h>
#include "client/tarantool/tc_opt.h" #include "client/tarantool/tc_opt.h"
...@@ -79,6 +80,42 @@ void tc_error(char *fmt, ...) { ...@@ -79,6 +80,42 @@ void tc_error(char *fmt, ...) {
tc_printf("error: %s\n", msg); tc_printf("error: %s\n", msg);
exit(1); exit(1);
} }
static int get_admin_port(void)
{
char *e = NULL;
tc_query("call box.dostring('return box.cfg.admin_port')", &e);
struct tnt_iter i, it, ifl;
tnt_iter_reply(&i, tc.net);
struct tnt_reply *r = TNT_IREPLY_PTR(&i);
if (!tnt_next(&i)) {
tnt_iter_free(&i);
}
if (tnt_error(tc.net) != TNT_EOK) {
tc_error(tc_query_error("%s ERROR, %s",
tc_query_op(r),
tnt_strerror(tc.net)));
} else if (r->code != 0) {
tc_error(tc_query_error("%s ERROR, %s (%s)",
tc_query_op(r), ((r->error) ? r->error : ""),
tnt_strerror(tc.net)));
}
tnt_iter_list(&it, TNT_REPLY_LIST(r));
if (!tnt_next(&it)) {
tnt_iter_free(&it);
tnt_iter_free(&i);
}
struct tnt_tuple *tu = TNT_ILIST_TUPLE(&it);
tnt_iter(&ifl, tu);
if (!tnt_next(&ifl)) { goto end; }
int port = *((uint32_t* )TNT_IFIELD_DATA(&ifl));
end:
tnt_iter_free(&ifl);
tnt_iter_free(&it);
tnt_iter_free(&i);
if (e != NULL)
free(e);
return port;
}
static void tc_connect(void) static void tc_connect(void)
{ {
...@@ -98,6 +135,8 @@ static void tc_connect(void) ...@@ -98,6 +135,8 @@ static void tc_connect(void)
/* connecting to server */ /* connecting to server */
if (tnt_connect(tc.net) == -1) if (tnt_connect(tc.net) == -1)
tc_error("%s", tnt_strerror(tc.net)); tc_error("%s", tnt_strerror(tc.net));
if (tc.opt.port_admin == 0)
tc.opt.port_admin = get_admin_port();
} }
static int get_primary_port(void) static int get_primary_port(void)
...@@ -125,6 +164,17 @@ static void tc_connect_admin(void) ...@@ -125,6 +164,17 @@ static void tc_connect_admin(void)
tc.opt.port = get_primary_port(); tc.opt.port = get_primary_port();
} }
static void tc_connect_both(void)
{
if (!tc.opt.port && tc.opt.port_admin) {
tc_connect_admin();
tc_connect();
} else {
tc_connect();
tc_connect_admin();
}
}
static void tc_validate(void) static void tc_validate(void)
{ {
tc.opt.xlog_printer = tc_print_getxlogcb(tc.opt.format); tc.opt.xlog_printer = tc_print_getxlogcb(tc.opt.format);
...@@ -165,13 +215,11 @@ int main(int argc, char *argv[]) ...@@ -165,13 +215,11 @@ int main(int argc, char *argv[])
rc = tc_store_play(); rc = tc_store_play();
break; break;
case TC_OPT_CMD: case TC_OPT_CMD:
tc_connect_admin(); tc_connect_both();
tc_connect();
rc = tc_cli_cmdv(); rc = tc_cli_cmdv();
break; break;
case TC_OPT_INTERACTIVE: case TC_OPT_INTERACTIVE:
tc_connect_admin(); tc_connect_both();
tc_connect();
rc = tc_cli(); rc = tc_cli();
break; break;
} }
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#define TC_DEFAULT_HOST "localhost" #define TC_DEFAULT_HOST "localhost"
#define TC_DEFAULT_PORT_ADMIN 33015
/* supported cli options */ /* supported cli options */
static const void *tc_options_def = gopt_start( static const void *tc_options_def = gopt_start(
...@@ -120,7 +119,7 @@ enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv) ...@@ -120,7 +119,7 @@ enum tc_opt_mode tc_opt_init(struct tc_opt *opt, int argc, char **argv)
opt->port = atoi(arg); opt->port = atoi(arg);
/* server admin port */ /* server admin port */
opt->port_admin = TC_DEFAULT_PORT_ADMIN; opt->port_admin = 0;
if (gopt_arg(tc_options, 'a', &arg)) if (gopt_arg(tc_options, 'a', &arg))
opt->port_admin = atoi(arg); opt->port_admin = atoi(arg);
......
...@@ -60,7 +60,7 @@ char *tc_query_type(uint32_t type) { ...@@ -60,7 +60,7 @@ char *tc_query_type(uint32_t type) {
return "Unknown"; return "Unknown";
} }
static char *tc_query_op(struct tnt_reply *r) { char *tc_query_op(struct tnt_reply *r) {
return tc_query_type(r->op); return tc_query_type(r->op);
} }
...@@ -73,7 +73,7 @@ int tc_query_printer(struct tnt_reply *r, void *ptr, char **e) { ...@@ -73,7 +73,7 @@ int tc_query_printer(struct tnt_reply *r, void *ptr, char **e) {
return 0; return 0;
} }
static char *tc_query_error(char *fmt, ...) { char *tc_query_error(char *fmt, ...) {
char msg[256]; char msg[256];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
......
...@@ -41,4 +41,8 @@ int tc_query(char *q, char **e); ...@@ -41,4 +41,8 @@ int tc_query(char *q, char **e);
int tc_query_admin_printer(char *r, char **e); int tc_query_admin_printer(char *r, char **e);
int tc_query_admin(char *q, tc_query_admin_t cb, char **e); int tc_query_admin(char *q, tc_query_admin_t cb, char **e);
char *tc_query_error(char *fmt, ...);
char *tc_query_op(struct tnt_reply *r);
#endif /* TC_QUERY_H_INCLUDED */ #endif /* TC_QUERY_H_INCLUDED */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment