From: Olga Arkhangelskaia <arkholga@tarantool.org> To: tarantool-patches@freelists.org Cc: Olga Arkhangelskaia <arkholga@tarantool.org> Subject: [tarantool-patches] [PATCH v2 1/2] Fixed non-informative error messages for log conf. Date: Wed, 1 Aug 2018 14:07:09 +0300 [thread overview] Message-ID: <20180801110710.10292-2-arkholga@tarantool.org> (raw) In-Reply-To: <20180801110710.10292-1-arkholga@tarantool.org> 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)
next prev parent reply other threads:[~2018-08-01 11:07 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-08-01 11:07 [tarantool-patches] [PATCH v2 0/2] logger non inf error Olga Arkhangelskaia 2018-08-01 11:07 ` Olga Arkhangelskaia [this message] 2018-08-01 12:32 ` [tarantool-patches] [PATCH v2 1/2] Fixed non-informative error messages for log conf Vladimir Davydov 2018-08-01 11:07 ` [tarantool-patches] [PATCH v2 2/2] box-tap: test to check logger invalid config Olga Arkhangelskaia 2018-08-01 12:39 ` Vladimir Davydov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180801110710.10292-2-arkholga@tarantool.org \ --to=arkholga@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH v2 1/2] Fixed non-informative error messages for log conf.' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox