From 3a0b40a6c7d1efa1d61b4b54e30ed0f2a5276b78 Mon Sep 17 00:00:00 2001
From: Eugine Blikh <bigbes@gmail.com>
Date: Tue, 10 Sep 2013 14:48:47 +0400
Subject: [PATCH] Add backwards compatibility

---
 client/tarantool/tc.c | 45 +++++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/client/tarantool/tc.c b/client/tarantool/tc.c
index c704ff80bd..8c7df4a30a 100644
--- a/client/tarantool/tc.c
+++ b/client/tarantool/tc.c
@@ -51,6 +51,7 @@
 #include "client/tarantool/tc_print_xlog.h"
 
 #define TC_DEFAULT_PORT 33013
+#define TC_ERR_CMD "---\nunknown command. try typing help.\n...\n"
 
 struct tc tc;
 
@@ -100,6 +101,34 @@ static void tc_connect(void)
 		tc_error("%s", tnt_strerror(tc.net));
 }
 
+static char *send_cmd(char *cmd)
+{
+	size_t size = 0;
+	char *reply = NULL;
+	if (tc_admin_query(&tc.admin, cmd) == -1)
+		tc_error("cannot send query");
+	if (tc_admin_reply(&tc.admin, &reply, &size) == -1)
+		tc_error("cannot recv query");
+	if (strcmp(reply, TC_ERR_CMD) == 0) {
+		free(reply);
+		return NULL;
+	}
+	return reply;
+}
+
+static int get_primary_port()
+{
+	int port = 0;
+	char *reply = send_cmd("box.cfg.primary_port");
+	if (reply == NULL)
+		reply = send_cmd("lua box.cfg.primary_port");
+	if (reply != NULL) {
+		sscanf(reply, "---\n - %d\n...", &port);
+		free(reply);
+	}
+	return port;
+}
+
 static void tc_connect_admin(void)
 {
 
@@ -107,20 +136,8 @@ static void tc_connect_admin(void)
 			     tc.opt.host,
 			     tc.opt.port_admin) == -1)
 		tc_error("admin console connection failed");
-	if (tc.opt.port == 0) {
-		char *reply = NULL;
-		size_t size = 0;
-		int port = 0;
-		if (tc_admin_query(&tc.admin, "box.cfg.primary_port") == -1)
-			tc_error("cannot send query");
-		if (tc_admin_reply(&tc.admin, &reply, &size) == -1)
-			tc_error("cannot recv query");
-		sscanf(reply, "---\n - %d\n...", &port);
-		if (port < 1024)
-			tc_error("cannot parse port number: %d", port);
-		tc.opt.port = port;
-		free(reply);
-	}
+	if (tc.opt.port == 0)
+		tc.opt.port = get_primary_port();
 }
 
 static void tc_validate(void)
-- 
GitLab