From e15941ff076d13649da3d33e7e9f6d6a787c48e1 Mon Sep 17 00:00:00 2001
From: Sulverus <sulverus@gmail.com>
Date: Fri, 29 May 2015 19:10:53 +0300
Subject: [PATCH] raw socket write replaced with console io replaced with fio

---
 extra/dist/tarantoolctl | 35 ++++++++++++++++++++++++++---------
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/extra/dist/tarantoolctl b/extra/dist/tarantoolctl
index d6c5aca165..0fd78576b8 100755
--- a/extra/dist/tarantoolctl
+++ b/extra/dist/tarantoolctl
@@ -103,6 +103,8 @@ local socket = require 'socket'
 local ffi = require 'ffi'
 local os = require 'os'
 local fiber = require 'fiber'
+local digest = require 'digest'
+local urilib = require 'uri'
 
 ffi.cdef[[ int kill(int pid, int sig); ]]
 
@@ -291,6 +293,21 @@ local function mkdir(dirname)
     end
 end
 
+local function read_file(filename)
+    local file = fio.open(filename, {'O_RDONLY'})
+    local buf = {}
+    local i = 1
+
+    while true do
+        buf[i] = file:read(1024)
+        if buf[i] == '' then
+            break
+        end
+        i = i + 1
+    end
+    return table.concat(buf)
+end
+
 function mk_default_dirs(cfg)
     -- create pid_dir
     pid_dir = fio.dirname(cfg.pid_file)
@@ -506,8 +523,7 @@ elseif cmd == 'reload' then
             os.exit(1)
         end
     end
-    local file = io.open(filename, 'rb')
-    local content = file:read('*all')
+    content = digest.base64_encode(read_file(filename))
 
     if fio.stat(console_sock) == nil then
         log.warn("pid file exists, but the control socket (%s) doesn't",
@@ -515,13 +531,14 @@ elseif cmd == 'reload' then
         os.exit(2)
     end
 
-    local s = socket.tcp_connect('unix/', console_sock)
-    if s == nil then
-        log.warn("Can't access control socket %s", console_sock)
-        os.exit(3)
-    end
-    s:write("loadstring('" .. content .. "')()\n")
-    s:close()
+    local u = urilib.parse(console_sock)
+    local remote = require('net.box'):new(u.host, u.service,
+        { user = u.login, password = u.password })
+    local code = string.format(
+        'loadstring(require("digest").base64_decode([[%s]]))()',
+        content
+    )
+    remote:console(code)
 
     os.exit(0)
 else
-- 
GitLab