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 50C622A9F9 for ; Mon, 15 Apr 2019 08:55:56 -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 npUf06f1xP7I for ; Mon, 15 Apr 2019 08:55:56 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 0303A2A9C7 for ; Mon, 15 Apr 2019 08:55:55 -0400 (EDT) Date: Mon, 15 Apr 2019 15:55:46 +0300 From: Alexander Turenko Subject: [tarantool-patches] Re: [PATCH] tarantoolctl: remove metatable assumptions in start() Message-ID: <20190415125545.hesq625tephx6hxo@tkn_work_nb> References: <20190327134014.56676-1-roman.habibov@tarantool.org> <20190401054304.kofvdg3uz6fzwl5d@tkn_work_nb> <20190411145725.il4veadyw4lcktj2@tkn_work_nb> <80D84297-4781-41C1-9E70-14712A77BA40@tarantool.org> <20190414224150.gcv2hbmazhri7o5w@tkn_work_nb> <93D2FEAD-1FF5-412B-8708-104FFCA6D517@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <93D2FEAD-1FF5-412B-8708-104FFCA6D517@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: Roman Khabibov Cc: tarantool-patches@freelists.org, Kirill Yukhin LGTM. Kirill, please, proceed. https://github.com/tarantool/tarantool/issues/3953 https://github.com/tarantool/tarantool/compare/romanhabibov/gh-3953-tctl WBR, Alexander Turenko. On Mon, Apr 15, 2019 at 01:59:31PM +0300, Roman Khabibov wrote: > > > > On Apr 15, 2019, at 1:41 AM, Alexander Turenko wrote: > > > > The code is okay, but I would clarify the commit message a bit. > > > >>>> > >>>> There was assumpted uninitialized metamethods of box.cfg{} if user > >>>> did't call it in his instance. > >>> > >>> This sentence raises more questions then give answers. What is > >>> 'uninitialized metamethods'? Whether 'of box.cfg{}' means result of the > >>> call or a new value of the 'cfg' field of the 'box' table? > >>> > >>> Also I doubt 'There was assumpted' is valid phrase. > >> > >> tarantoolctl: raise error when box.cfg isn't called > >> > >> There was no check whether box.cfg{} was initialized in an > >> instance. If so, an error should be raised. > > > > 'box' can be initialized (it is a module), 'box.cfg' can be called, but > > we usually use parentheses to mark a name as a function, so 'box.cfg()' > > can be called. Technically 'box.cfg{} was initialized' is not correct. > > > > 'If so' here point to the positive case (when called). > > > > Let me propose wording that will satisfy me: > > > >> Added a check whether box.cfg() is called within an instance file. If > >> box.cfg() is missed, point a user the reason of a fail explicitly. > >> > >> Before this commit the error was look so: > >> > >> /usr/bin/tarantoolctl:541: attempt to index a nil value > > > > Also don't forget to add 'Fixes #xxxx' clause to the end of the commit > > message. > Done. > > commit 7aba9a68b1139738fc3da1bfa39c490f3afdfc5e > Author: Roman Khabibov > Date: Mon Mar 25 20:52:05 2019 +0300 > > tarantoolctl: raise error when box.cfg isn't called > > Added a check whether box.cfg() is called within an instance > file. If box.cfg() is missed, point a user the reason of a > fail explicitly. > > Before this commit the error was look so: > > /usr/bin/tarantoolctl:541: attempt to index a nil value > > Closes #3953 > > diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in > index 47fcf895f..37ded5333 100755 > --- a/extra/dist/tarantoolctl.in > +++ b/extra/dist/tarantoolctl.in > @@ -547,8 +547,13 @@ local function start() > end > os.exit(1) > end > - local old_call = getmetatable(box.cfg).__call > - getmetatable(box.cfg).__call = function(old_cfg, cfg) > + local box_cfg_mt = getmetatable(box.cfg) > + if box_cfg_mt == nil then > + log.error('box.cfg() is not called in an instance file') > + os.exit(1) > + end > + local old_call = box_cfg_mt.__call > + box_cfg_mt.__call = function(old_cfg, cfg) > if old_cfg.pid_file ~= nil and cfg ~= nil and cfg.pid_file ~= nil then > cfg.pid_file = old_cfg.pid_file > end > diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua > index db046e03f..7d7c63371 100755 > --- a/test/app-tap/tarantoolctl.test.lua > +++ b/test/app-tap/tarantoolctl.test.lua > @@ -163,12 +163,14 @@ test:plan(7) > -- must be stopped afterwards > do > local dir = fio.tempdir() > - local code = [[ box.cfg{memtx_memory = 104857600} ]] > - create_script(dir, 'script.lua', code) > + create_script(dir, 'script.lua', [[ box.cfg{memtx_memory = 104857600} ]]) > + create_script(dir, 'no_box_cfg.lua', [[ print('Hi!') ]]) > > local status, err = pcall(function() > test:test("basic test", function(test_i) > - test_i:plan(16) > + test_i:plan(18) > + check_ok(test_i, dir, 'start', 'no_box_cfg', 1, nil, "Starting instance", > + "box.cfg() is not called in an instance file") > check_ok(test_i, dir, 'start', 'script', 0, nil, "Starting instance") > tctl_wait_start(dir, 'script') > check_ok(test_i, dir, 'status', 'script', 0, nil, "is running")