[tarantool-patches] [PATCH v2 2/2] say: take getaddrinfo() errors into account

Roman Khabibov roman.habibov at tarantool.org
Tue Jun 25 16:38:27 MSK 2019


Before this patch, branch when getaddrinfo() returns error codes
couldn't be reached on Mac OS, because they are greater than 0 on
Mac OS (checking for errors was rc < 0).

Part of #4138
---
 src/lib/core/say.c        |  3 ++-
 test/box-tap/cfg.test.lua | 19 ++++++++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/lib/core/say.c b/src/lib/core/say.c
index 0b2cf2c34..c927f9fc0 100644
--- a/src/lib/core/say.c
+++ b/src/lib/core/say.c
@@ -506,7 +506,7 @@ syslog_connect_remote(const char *server_address)
 	hints.ai_protocol = IPPROTO_UDP;
 
 	ret = getaddrinfo(remote, portnum, &hints, &inf);
-	if (ret < 0) {
+	if (ret != 0) {
 		errno = EIO;
 		diag_set(SystemError, "getaddrinfo: %s",
 			 gai_strerror(ret));
@@ -594,6 +594,7 @@ log_syslog_init(struct log *log, const char *init_str)
 	log->fd = log_syslog_connect(log);
 	if (log->fd < 0) {
 		/* syslog indent is freed in atexit(). */
+		diag_log();
 		diag_set(SystemError, "syslog logger: %s", strerror(errno));
 		return -1;
 	}
diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua
index 55de5e41c..d92e9140d 100755
--- a/test/box-tap/cfg.test.lua
+++ b/test/box-tap/cfg.test.lua
@@ -6,7 +6,7 @@ local socket = require('socket')
 local fio = require('fio')
 local uuid = require('uuid')
 local msgpack = require('msgpack')
-test:plan(104)
+test:plan(105)
 
 --------------------------------------------------------------------------------
 -- Invalid values
@@ -566,6 +566,23 @@ os.exit(0)
 ]]
 test:is(run_script(code), 0, "log_nonblock")
 
+--
+-- gh-4138: check getaddrinfo() error and panic after that.
+--
+code=[[
+local socket = require('socket')
+local log = require('log')
+local fio = require('fio')
+
+path = fio.pathjoin(fio.cwd(), 'log_unix_socket_test.sock')
+unix_socket = socket('AF_UNIX', 'SOCK_DGRAM', 0)
+unix_socket:bind('unix/', path)
+
+opt = string.format("syslog:server=non_exists_hostname:%s,identity=tarantool", path)
+box.cfg{log = opt, log_nonblock=true}
+]]
+test:is(run_script(code), PANIC, "log_nonblock")
+
 --
 -- Crash (instead of panic) when trying to recover a huge tuple.
 --
-- 
2.20.1 (Apple Git-117)





More information about the Tarantool-patches mailing list