Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v2] lua: fix for option pid_file overwritten by tarantoolctl
@ 2018-07-31 14:35 Konstantin Belyavskiy
  2018-08-13  4:36 ` [tarantool-patches] " Georgy Kirichenko
  2018-08-21 15:24 ` [tarantool-patches] " Vladimir Davydov
  0 siblings, 2 replies; 4+ messages in thread
From: Konstantin Belyavskiy @ 2018-07-31 14:35 UTC (permalink / raw)
  To: tarantool-patches

During startup tarantoolctl ignores 'pid_file' option and set it to
default value.
This cause a fault if user tries to execute config with option set.
In case of being started with tarantoolctl shadow this option with
additional wrapper around box.cfg.

Changes in V2:
 Use local defined closure instead of a global function with a
 variable (based on @GeorgyKirichenko proposal).

Closes #3214
---
ticket: https://github.com/tarantool/tarantool/issues/3214
branch: https://github.com/tarantool/tarantool/tree/kbelyavs/gh-3214-tarantoolctl-pidfile-fix
 extra/dist/tarantoolctl.in |  7 +++++++
 test/box/cfg.result        | 30 ++++++++++++++++++++++++++++++
 test/box/cfg.test.lua      | 12 ++++++++++++
 3 files changed, 49 insertions(+)

diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in
index 507ebe8bf..4c7dfa2f1 100755
--- a/extra/dist/tarantoolctl.in
+++ b/extra/dist/tarantoolctl.in
@@ -527,6 +527,13 @@ local function start()
         end
         os.exit(1)
     end
+    local old_call = getmetatable(box.cfg).__call
+    getmetatable(box.cfg).__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
+        old_call(old_cfg, cfg)
+    end
     return 0
 end
 
diff --git a/test/box/cfg.result b/test/box/cfg.result
index cda7aa0d3..a2df83310 100644
--- a/test/box/cfg.result
+++ b/test/box/cfg.result
@@ -365,6 +365,36 @@ test_run:cmd("cleanup server cfg_tester4")
 - true
 ...
 --------------------------------------------------------------------------------
+-- Check fix for pid_file option overwritten by tarantoolctl
+--------------------------------------------------------------------------------
+test_run:cmd('create server cfg_tester5 with script = "box/lua/cfg_test1.lua"')
+---
+- true
+...
+test_run:cmd("start server cfg_tester5")
+---
+- true
+...
+test_run:cmd('switch cfg_tester5')
+---
+- true
+...
+box.cfg{pid_file = "current.pid"}
+---
+...
+test_run:cmd("switch default")
+---
+- true
+...
+test_run:cmd("stop server cfg_tester5")
+---
+- true
+...
+test_run:cmd("cleanup server cfg_tester5")
+---
+- true
+...
+--------------------------------------------------------------------------------
 -- Check that 'vinyl_dir' cfg option is not checked as long as
 -- there is no vinyl indexes (issue #2664)
 --------------------------------------------------------------------------------
diff --git a/test/box/cfg.test.lua b/test/box/cfg.test.lua
index dbb463025..712a165bb 100644
--- a/test/box/cfg.test.lua
+++ b/test/box/cfg.test.lua
@@ -69,6 +69,18 @@ test_run:cmd("switch default")
 test_run:cmd("stop server cfg_tester4")
 test_run:cmd("cleanup server cfg_tester4")
 
+--------------------------------------------------------------------------------
+-- Check fix for pid_file option overwritten by tarantoolctl
+--------------------------------------------------------------------------------
+
+test_run:cmd('create server cfg_tester5 with script = "box/lua/cfg_test1.lua"')
+test_run:cmd("start server cfg_tester5")
+test_run:cmd('switch cfg_tester5')
+box.cfg{pid_file = "current.pid"}
+test_run:cmd("switch default")
+test_run:cmd("stop server cfg_tester5")
+test_run:cmd("cleanup server cfg_tester5")
+
 --------------------------------------------------------------------------------
 -- Check that 'vinyl_dir' cfg option is not checked as long as
 -- there is no vinyl indexes (issue #2664)
-- 
2.14.3 (Apple Git-98)

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [tarantool-patches] [PATCH v2] lua: fix for option pid_file overwritten by tarantoolctl
@ 2018-07-23 17:07 Konstantin Belyavskiy
  0 siblings, 0 replies; 4+ messages in thread
From: Konstantin Belyavskiy @ 2018-07-23 17:07 UTC (permalink / raw)
  To: tarantool-patches

During startup tarantoolctl ignores 'pid_file' option and set it to
default value.
This cause a fault if user tries to execute config with option set.
In case of being started with tarantoolctl shadow this option with
additional wrapper around box.cfg.

Closes #3214
---
ticket: https://github.com/tarantool/tarantool/issues/3214
branch: https://github.com/tarantool/tarantool/tree/kbelyavs/gh-3214-tarantoolctl-pidfile-fix
 extra/dist/tarantoolctl.in | 11 +++++++++++
 test/box/cfg.result        | 30 ++++++++++++++++++++++++++++++
 test/box/cfg.test.lua      | 12 ++++++++++++
 3 files changed, 53 insertions(+)

diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in
index 507ebe8bf..f60c910d8 100755
--- a/extra/dist/tarantoolctl.in
+++ b/extra/dist/tarantoolctl.in
@@ -471,6 +471,15 @@ local function wrapper_cfg(cfg)
     return data
 end
 
+cfg_callback = nil
+
+function wrapper_cfg_reload(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
+    cfg_callback(old_cfg, cfg)
+end
+
 -- It's not 100% result guaranteed function, but it's ok for most cases
 -- Won't help in multiple race-conditions
 -- Returns nil if Tarantool already started, PID otherwise
@@ -527,6 +536,8 @@ local function start()
         end
         os.exit(1)
     end
+    cfg_callback = getmetatable(box.cfg).__call
+    getmetatable(box.cfg).__call = wrapper_cfg_reload
     return 0
 end
 
diff --git a/test/box/cfg.result b/test/box/cfg.result
index cda7aa0d3..a2df83310 100644
--- a/test/box/cfg.result
+++ b/test/box/cfg.result
@@ -365,6 +365,36 @@ test_run:cmd("cleanup server cfg_tester4")
 - true
 ...
 --------------------------------------------------------------------------------
+-- Check fix for pid_file option overwritten by tarantoolctl
+--------------------------------------------------------------------------------
+test_run:cmd('create server cfg_tester5 with script = "box/lua/cfg_test1.lua"')
+---
+- true
+...
+test_run:cmd("start server cfg_tester5")
+---
+- true
+...
+test_run:cmd('switch cfg_tester5')
+---
+- true
+...
+box.cfg{pid_file = "current.pid"}
+---
+...
+test_run:cmd("switch default")
+---
+- true
+...
+test_run:cmd("stop server cfg_tester5")
+---
+- true
+...
+test_run:cmd("cleanup server cfg_tester5")
+---
+- true
+...
+--------------------------------------------------------------------------------
 -- Check that 'vinyl_dir' cfg option is not checked as long as
 -- there is no vinyl indexes (issue #2664)
 --------------------------------------------------------------------------------
diff --git a/test/box/cfg.test.lua b/test/box/cfg.test.lua
index dbb463025..712a165bb 100644
--- a/test/box/cfg.test.lua
+++ b/test/box/cfg.test.lua
@@ -69,6 +69,18 @@ test_run:cmd("switch default")
 test_run:cmd("stop server cfg_tester4")
 test_run:cmd("cleanup server cfg_tester4")
 
+--------------------------------------------------------------------------------
+-- Check fix for pid_file option overwritten by tarantoolctl
+--------------------------------------------------------------------------------
+
+test_run:cmd('create server cfg_tester5 with script = "box/lua/cfg_test1.lua"')
+test_run:cmd("start server cfg_tester5")
+test_run:cmd('switch cfg_tester5')
+box.cfg{pid_file = "current.pid"}
+test_run:cmd("switch default")
+test_run:cmd("stop server cfg_tester5")
+test_run:cmd("cleanup server cfg_tester5")
+
 --------------------------------------------------------------------------------
 -- Check that 'vinyl_dir' cfg option is not checked as long as
 -- there is no vinyl indexes (issue #2664)
-- 
2.14.3 (Apple Git-98)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-08-21 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-31 14:35 [tarantool-patches] [PATCH v2] lua: fix for option pid_file overwritten by tarantoolctl Konstantin Belyavskiy
2018-08-13  4:36 ` [tarantool-patches] " Georgy Kirichenko
2018-08-21 15:24 ` [tarantool-patches] " Vladimir Davydov
  -- strict thread matches above, loose matches on Subject: below --
2018-07-23 17:07 Konstantin Belyavskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox