From fec40ea544c5bf87c713a5e70a6997d3edd15a68 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 18 Apr 2018 11:52:05 +1000 Subject: [PATCH] ctdb-common: Refactor log backend parsing code This will allow to add a validator for logging specification. Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/common/logging.c | 121 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/ctdb/common/logging.c b/ctdb/common/logging.c index f68c1b9d457..0a46b00eb11 100644 --- a/ctdb/common/logging.c +++ b/ctdb/common/logging.c @@ -528,27 +528,78 @@ static int syslog_log_setup(TALLOC_CTX *mem_ctx, const char *option, return EINVAL; } +struct log_backend { + const char *name; + int (*setup)(TALLOC_CTX *mem_ctx, + const char *option, + const char *app_name); +}; + +static struct log_backend log_backend[] = { + { + .name = "file", + .setup = file_log_setup, + }, + { + .name = "syslog", + .setup = syslog_log_setup, + }, +}; + +static int log_backend_parse(TALLOC_CTX *mem_ctx, + const char *logging, + struct log_backend **backend, + char **backend_option) +{ + struct log_backend *b = NULL; + char *t, *name, *option; + int i; + + t = talloc_strdup(mem_ctx, logging); + if (t == NULL) { + return ENOMEM; + } + + name = strtok(t, ":"); + if (name == NULL) { + talloc_free(t); + return EINVAL; + } + option = strtok(NULL, ":"); + + for (i=0; isetup(mem_ctx, option, app_name); + talloc_free(option); return ret; } -- 2.11.4.GIT