From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 28E8525075 for ; Mon, 16 Jul 2018 04:27:11 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x8O0ZgoDbS5U for ; Mon, 16 Jul 2018 04:27:10 -0400 (EDT) Received: from smtp41.i.mail.ru (smtp41.i.mail.ru [94.100.177.101]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 341A625023 for ; Mon, 16 Jul 2018 04:27:10 -0400 (EDT) From: Serge Petrenko Subject: [tarantool-patches] [PATCH] tarantoolctl: return an error on enter to a dead socket. Date: Mon, 16 Jul 2018 11:26:55 +0300 Message-Id: <20180716082655.42311-1-sergepetrenko@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Serge Petrenko Tarantoolctl enter didn't check whether connection to a socket was established if a socket file existed. It just executed a local console. Fix this by adding a check and an error, also add a test case. Closes #3364 --- https://github.com/tarantool/tarantool/issues/3364 https://github.com/tarantool/tarantool/tree/sergepetrenko/gh-3364-tarantoolctl-enter-fix extra/dist/tarantoolctl.in | 19 ++++++++++++------- test/app-tap/tarantoolctl.test.lua | 29 ++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 2dd5d74ef..8085ede63 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -638,15 +638,20 @@ local function enter() end return 1 end - - local cmd = string.format( - "require('console').connect('%s', { connect_timeout = %s })", - console_sock, TIMEOUT_INFINITY - ) - - console.on_start(function(self) self:eval(cmd) end) + local status, ret + console.on_start(function(self) + pcall(console.connect, console_sock, + {connect_timeout = TIMEOUT_INFINITY}) + if not status then + log.error("Can't connect to %s (%s)", console_sock_path, ret) + self.running = false + end + end) console.on_client_disconnect(function(self) self.running = false end) console.start() + if not status then + return 1 + end return 0 end diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 6946c8312..f40a90c55 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -150,7 +150,7 @@ local function check_ok(test, dir, cmd, args, e_res, e_stdout, e_stderr) end local test = tap.test('tarantoolctl') -test:plan(6) +test:plan(7) -- basic start/stop test -- must be stopped afterwards @@ -250,6 +250,33 @@ do end end +-- check enter +do + local dir = fio.tempdir() + + local code = [[ box.cfg{} ]] + create_script(dir, 'script.lua', code) + + local status, err = pcall(function() + test:test("check error codes in case of enter", function(test_i) + test_i:plan(6) + check_ok(test_i, dir, 'enter', 'script', 1, nil, "Can't connect to") + check_ok(test_i, dir, 'start', 'script', 0) + os.execute(("kill $(cat %s/script.pid)"):format(dir)) + check_ok(test_i, dir, 'enter', 'script', 1, nil, "Can't connect to") + check_ok(test_i, dir, 'stop','script', 0) + end) + end) + + cleanup_instance(dir, 'script') + recursive_rmdir(dir) + + if status == false then + prit(("Error: %s"):format(err)) + os.exit() + end +end + -- check basic help do local dir = fio.tempdir() -- 2.15.2 (Apple Git-101.1)