Skip to content

Commit

Permalink
launcher: add fix for long socket paths
Browse files Browse the repository at this point in the history
Now relative path is used instead of real for console socket.
It is used to prevent console socket path from being too long.

Part of #124
  • Loading branch information
better0fdead committed Nov 14, 2022
1 parent 0020a79 commit 9a6297f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
21 changes: 19 additions & 2 deletions cli/running/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,26 @@ func (inst *Instance) Start() error {
return err
}
inst.Cmd.Env = append(os.Environ(), "TT_CLI_INSTANCE="+inst.appPath)
inst.Cmd.Env = append(inst.Cmd.Env,
"TT_CLI_CONSOLE_SOCKET="+inst.consoleSocket)

// It became common that console socket path is longer than 108 symbols(sun_path limit).
// To reduce length of path we use relative path
// with chdir into a directory of console socket.
// e.g foo/bar/123.sock -> ./123.sock
if inst.consoleSocket != "" {
if len("./"+filepath.Base(inst.consoleSocket)) > 108 {
return fmt.Errorf("socket name is longer than 106 symbols: %s",
filepath.Base(inst.consoleSocket))
}
inst.Cmd.Env = append(inst.Cmd.Env,
"TT_CLI_CONSOLE_SOCKET="+"unix/:./"+filepath.Base(inst.consoleSocket))
inst.Cmd.Env = append(inst.Cmd.Env,
"TT_CLI_CONSOLE_SOCKET_DIR="+filepath.Dir(inst.consoleSocket))
}
workDir, err := os.Getwd()
if err != nil {
return err
}
inst.Cmd.Env = append(inst.Cmd.Env, "TT_CLI_WORK_DIR="+workDir)
dataDirAbs := ""
if dataDirAbs, err = filepath.Abs(inst.dataDir); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cli/running/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func TestInstanceLogger(t *testing.T) {
defer writer.Close()
defer reader.Close()
logger := ttlog.NewCustomLogger(writer, "", 0)

inst := startTestInstance(t, "log_check_test_app", "", logger)
consoleSock := ""
inst := startTestInstance(t, "log_check_test_app", consoleSock, logger)
t.Cleanup(func() { cleanupTestInstance(inst) })

msg := "Check Log.\n"
Expand Down
26 changes: 25 additions & 1 deletion cli/running/lua/launcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ local origin_cfg = box.cfg

--- Wrapper for cfg to push our values over tarantool.
local function cfg_wrapper(cfg)
ffi.cdef([[
int chdir(const char *path);
]])
ffi.C.chdir(os.getenv('TT_CLI_CONSOLE_SOCKET_DIR'))
local cfg = cfg or {}
local tt_cfg = {}
tt_cfg.wal_dir = os.getenv('TT_WAL_DIR')
Expand All @@ -54,7 +58,8 @@ local function cfg_wrapper(cfg)
end
end
local success, data = pcall(origin_cfg, cfg)
if not success then
ffi.C.chdir(os.getenv('TT_CLI_WORK_DIR'))
if not success then
log.error('Someting wrong happened when tried to set dataDir.')
end
return data
Expand Down Expand Up @@ -102,6 +107,19 @@ local function start_instance()
ffi.C.setlinebuf(ffi.C.stdout)
end

ffi.cdef([[
int chdir(const char *path);
]])

-- It became common that console socket path is longer than 108 symbols(sun_path limit).
-- To reduce length of path we use relative path with
-- chdir into a directory of console socket.
-- e.g foo/bar/123.sock -> ./123.sock
local console_sock_dir = os.getenv('TT_CLI_CONSOLE_SOCKET_DIR')
if console_sock_dir ~= nil and console_sock_dir ~= '' then
ffi.C.chdir(console_sock_dir)
end

-- If tarantool version is above 2.8.1, then can use environment variables
-- instead of wrapping cfg.
if not check_version({2,8,1,0}) then
Expand All @@ -127,6 +145,12 @@ local function start_instance()

end

-- After making console socket chdir back to work directory.
local work_dir = os.getenv('TT_CLI_WORK_DIR')
if work_dir ~= nil and work_dir ~= '' then
ffi.C.chdir(work_dir)
end

-- If stdin of the program was moved by command "tt run" to another fd
-- then we need to move it back.
-- It is used in cases when calling tarantool with "-" flag to hide input
Expand Down

0 comments on commit 9a6297f

Please sign in to comment.