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 D65ED267F8 for ; Tue, 17 Jul 2018 11:15:32 -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 4zb09LVebgZV for ; Tue, 17 Jul 2018 11:15:32 -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 8987F26BF5 for ; Tue, 17 Jul 2018 11:15:32 -0400 (EDT) From: Olga Arkhangelskaia Subject: [tarantool-patches] [PATCH 1/2] Ractoring in string validation of log parametrs Date: Tue, 17 Jul 2018 18:15:20 +0300 Message-Id: <20180717151521.34679-2-arkholga@tarantool.org> In-Reply-To: <20180717151521.34679-1-arkholga@tarantool.org> References: <20180717151521.34679-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 Removed unnecessary double check of log configuration string. Instead all log configuration ckecks were moved to separate function. v2: - Introduced new function say_check_cfg that encapsulates all checks. --- src/box/box.cc | 29 +---------------------------- src/say.c | 36 +++++++++++++++++++++++------------- src/say.h | 9 ++++----- 3 files changed, 28 insertions(+), 46 deletions(-) diff --git a/src/box/box.cc b/src/box/box.cc index 9252e82c1..9ef923616 100644 --- a/src/box/box.cc +++ b/src/box/box.cc @@ -362,36 +362,9 @@ box_check_say() diag_last_error(diag_get())->errmsg); } - if (say_check_init_str(log) == -1) { - - diag_raise(); - } - - if (type == SAY_LOGGER_SYSLOG) { - struct say_syslog_opts opts; - if (say_parse_syslog_opts(log, &opts) < 0) { - if (diag_last_error(diag_get())->type == - &type_IllegalParams) { - tnt_raise(ClientError, ER_CFG, "log", - diag_last_error(diag_get())->errmsg); - } - diag_raise(); - } - say_free_syslog_opts(&opts); - } - 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"); - } int log_nonblock = cfg_getb("log_nonblock"); - if (log_nonblock == 1 && type == SAY_LOGGER_FILE) { - tnt_raise(ClientError, ER_ILLEGAL_PARAMS, "log, log_nonblock"); - } + say_check_cfg(log, log_format, log_nonblock, type); } static enum say_format diff --git a/src/say.c b/src/say.c index 43124083c..501095b3e 100644 --- a/src/say.c +++ b/src/say.c @@ -952,25 +952,35 @@ write_to_syslog(struct log *log, int total) /** Loggers }}} */ /* - * Init string parser(s) + * Checks logger configuration */ - -int -say_check_init_str(const char *str) +void +say_check_cfg(const char *log, const char *log_format, + int log_nonblock, enum say_logger_type type) { - enum say_logger_type type; - if (say_parse_logger_type(&str, &type)) { - diag_set(IllegalParams, logger_syntax_reminder); - return -1; - } if (type == SAY_LOGGER_SYSLOG) { struct say_syslog_opts opts; - - if (say_parse_syslog_opts(str, &opts) < 0) - return -1; + int ret = say_parse_syslog_opts(log, &opts); say_free_syslog_opts(&opts); + if (ret < 0) { + diag_set(IllegalParams, "Incorrect option '%s'", log); + diag_raise(); + } + } + + enum say_format format = say_format_by_name(log_format); + if (format == say_format_MAX) { + diag_set(IllegalParams, + "for log_format expected 'plain' or 'json'"); + } + if (type == SAY_LOGGER_SYSLOG && format == SF_JSON) { + diag_set(IllegalParams, "Illegal parametrs log, log_format"); + diag_raise(); + } + if (log_nonblock == 1 && type == SAY_LOGGER_FILE) { + diag_set(IllegalParams, "Illegal parametrs log, log_nonblock"); + diag_raise(); } - return 0; } /** diff --git a/src/say.h b/src/say.h index ad3ba3417..88cf9bd78 100644 --- a/src/say.h +++ b/src/say.h @@ -371,12 +371,11 @@ CFORMAT(printf, 5, 0) extern sayfunc_t _say; log_say_level(log, S_SYSERROR, strerror(errno), format, ##__VA_ARGS__) /** - * validates logger init string; - * @returns 0 if validation passed or -1 - * with an error message written to diag + * Validates logger configuration; */ -int -say_check_init_str(const char *str); +void +say_check_cfg(const char *log, const char *log_format, + int log_nonblock, enum say_logger_type type); /* internals, for unit testing */ -- 2.14.3 (Apple Git-98)