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 D446D277AD for ; Wed, 1 Aug 2018 07:07:41 -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 mPzKSRSImsTk for ; Wed, 1 Aug 2018 07:07:41 -0400 (EDT) Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [94.100.177.103]) (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 8896127790 for ; Wed, 1 Aug 2018 07:07:41 -0400 (EDT) From: Olga Arkhangelskaia Subject: [tarantool-patches] [PATCH v2 1/2] Fixed non-informative error messages for log conf. Date: Wed, 1 Aug 2018 14:07:09 +0300 Message-Id: <20180801110710.10292-2-arkholga@tarantool.org> In-Reply-To: <20180801110710.10292-1-arkholga@tarantool.org> References: <20180801110710.10292-1-arkholga@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: tarantool-patches@freelists.org Cc: Olga Arkhangelskaia In case of bad or erroneous options for log configurations errors had ambiguous or absent messages. In some cases it lead to app crashes. Closes #3553 --- src/box/box.cc | 66 ++++++++++++++++++++++++++++++----------------- src/say.c | 5 ++-- test/box-tap/cfg.test.lua | 2 +- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 62fd05468..dc607c1ae 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -351,17 +351,41 @@ apply_initial_join_row(struct xstream *stream, struct xrow_header *row) /* {{{ configuration bindings */ +static enum say_format +box_check_log_format(const char *log_format) +{ + enum say_format format = say_format_by_name(log_format); + if (format == say_format_MAX) + tnt_raise(ClientError, ER_CFG, "log_format", + "expected 'plain' or 'json'"); + return format; +} + static void -box_check_say() +box_check_format_compatibility(enum say_format format, enum say_logger_type type) { - const char *log = cfg_gets("log"); - if (log == NULL) - return; - enum say_logger_type type; - if (say_parse_logger_type(&log, &type) < 0) { + if (type == SAY_LOGGER_SYSLOG && format == SF_JSON) { + tnt_raise(ClientError, ER_CFG, "log_format", + "'json' can't be used with syslog logger"); + } +} + +static enum say_logger_type +box_check_logger_type(const char **log) +{ + enum say_logger_type type = SAY_LOGGER_STDERR; + if (*log != NULL && say_parse_logger_type(log, &type) < 0) { tnt_raise(ClientError, ER_CFG, "log", diag_last_error(diag_get())->errmsg); } + return type; +} + +static void +box_check_say() +{ + const char *log = cfg_gets("log"); + enum say_logger_type type = box_check_logger_type(&log); if (type == SAY_LOGGER_SYSLOG) { struct say_syslog_opts opts; @@ -377,27 +401,18 @@ box_check_say() } const char *log_format = cfg_gets("log_format"); - enum say_format format = say_format_by_name(log_format); - if (format == say_format_MAX) - diag_set(ClientError, ER_CFG, "log_format", - "expected 'plain' or 'json'"); - if (type == SAY_LOGGER_SYSLOG && format == SF_JSON) { - tnt_raise(ClientError, ER_ILLEGAL_PARAMS, "log, log_format"); - } + enum say_format format = box_check_log_format(log_format); + box_check_format_compatibility(format, type); + int log_nonblock = cfg_getb("log_nonblock"); if (log_nonblock == 1 && type == SAY_LOGGER_FILE) { - tnt_raise(ClientError, ER_ILLEGAL_PARAMS, "log, log_nonblock"); + tnt_raise(ClientError, ER_CFG, "log_nonblock", + "true' can't be used with file logger type"); + } + if (log_nonblock == 1 && type == SAY_LOGGER_STDERR) { + tnt_raise(ClientError, ER_CFG, "log_nonblock", + "'true' can't be used with stderr logger type"); } -} - -static enum say_format -box_check_log_format(const char *log_format) -{ - enum say_format format = say_format_by_name(log_format); - if (format == say_format_MAX) - tnt_raise(ClientError, ER_CFG, "log_format", - "expected 'plain' or 'json'"); - return format; } static void @@ -745,7 +760,10 @@ box_set_log_level(void) void box_set_log_format(void) { + const char *log = cfg_gets("log"); enum say_format format = box_check_log_format(cfg_gets("log_format")); + static enum say_logger_type type = box_check_logger_type(&log); + box_check_format_compatibility(format, type); say_set_log_format(format); } diff --git a/src/say.c b/src/say.c index ac221dd19..01a0d150d 100644 --- a/src/say.c +++ b/src/say.c @@ -541,7 +541,6 @@ log_create(struct log *log, const char *init_str, int nonblock) if (init_str != NULL) { enum say_logger_type type; if (say_parse_logger_type(&init_str, &type)) { - diag_set(IllegalParams, logger_syntax_reminder); return -1; } int rc; @@ -989,8 +988,10 @@ say_parse_logger_type(const char **str, enum say_logger_type *type) *type = SAY_LOGGER_SYSLOG; else if (strchr(*str, ':') == NULL) *type = SAY_LOGGER_FILE; - else + else { + diag_set(IllegalParams, logger_syntax_reminder); return -1; + } return 0; } diff --git a/test/box-tap/cfg.test.lua b/test/box-tap/cfg.test.lua index ffafdbe42..ea6f4d646 100755 --- a/test/box-tap/cfg.test.lua +++ b/test/box-tap/cfg.test.lua @@ -51,7 +51,7 @@ invalid('vinyl_bloom_fpr', 1.1) local function invalid_combinations(name, val) local status, result = pcall(box.cfg, val) - test:ok(not status and result:match('Illegal'), 'invalid '..name) + test:ok(not status and result:match('Incorrect'), 'incompatible values'..name) end invalid_combinations("log, log_nonblock", {log = "1.log", log_nonblock = true}) -- 2.14.3 (Apple Git-98)