From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EC1E145BB9; Thu, 24 Oct 2024 05:21:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C9A6C43382; Thu, 24 Oct 2024 05:20:53 +0200 (CEST) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 03F2F43367 for ; Thu, 24 Oct 2024 05:20:44 +0200 (CEST) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-7203c431f93so363647b3a.1 for ; Wed, 23 Oct 2024 20:20:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1729740043; x=1730344843; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EjGJNAutxrkfiYhekpPRzeGK1WoofEQNPKqDONq8hh4=; b=y27+Pd3jxyCZpQ8GHCzWtU4yMps72sbHCMm6Jk6I1rLcYcv9MoYE6gX6a0aGLwo5zH e/dZGdC1t0rzT+Mg23GQcAwMBuQZFMa0XkMgDmHPLoDHCcmUnxUXNb4nuBSZeoL9ZY8w Gb80KROYUmfKNq81ePp26Tx1NeulXAg3iOgBkY3vLL/WP4RJEF1xM9AB1E1IpIzIWpRa +HhwUIQEE7oFQMxxxwx5neEXsP33FskPWfw4diihuBwb4eewzkTyOzggwTtPTklhRmcp 9GFcX6IUfPDMZhGgb7J5CMbh6YY9xzoxZQS0OJOoT56EwMXDwWIOsTtKgmroex2E1BnJ Es0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729740043; x=1730344843; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EjGJNAutxrkfiYhekpPRzeGK1WoofEQNPKqDONq8hh4=; b=m20F47URLuqh2Zt+kASyhtgWgWqo6OiapdCpkZ0YFk4ZHO65jmY5W4SzFhWvi4amz/ DQpi4ECR2WqoQCw6wF5oejFDueQ193iwwjQgsj/YBrvogJZYMTnH14T/S9OD9xZq6VT2 aKliNyWomautzk0k28ReV/WbKyH0BlN4JITYdZh+KMDd5NyhLoyN6Xd4BKeOPUURf8WL eqFvC98DAsHAt8Jwua3HQvqSNVbLiInLficxpJwPJh9StQtdQHPAiTEoYpxCveoS8Oz9 QYBqHv62bSfb8ULMpUXP3KiMAXGThvmU93vg2142Il4bxcwxZ3TsA5FD1Css/b24WrrV h2/w== X-Gm-Message-State: AOJu0Yzm39JRFN8AeGCKck80JEqDi8dsH92EQVvwA6aPjV37ti48nVnz 4YcsNk6jYgHpAAtmPufvkTWycQt+HVNU31FiUxJMM16IUBvzn0HOl1MuljHxZUSNtqCo2hEzGGS 1 X-Google-Smtp-Source: AGHT+IG2Hsdq4pRPNZU7/0hdguJv2mxvULttlFruh05Gb5KXajSV8UkCOEWDA5psYPCVkWOoEo2BwA== X-Received: by 2002:a05:6a00:3c94:b0:71e:7a56:3eaf with SMTP id d2e1a72fcca58-72030bba11fmr6645857b3a.24.1729740043042; Wed, 23 Oct 2024 20:20:43 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec1324d41sm6999533b3a.57.2024.10.23.20.20.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2024 20:20:42 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , =?UTF-8?q?Morten=20Br=C3=B8rup?= , Bruce Richardson , Chengwen Feng , Tyler Retzlaff , Dmitry Kozlyuk Subject: [PATCH v27 07/14] log: move handling of syslog facility out of eal Date: Wed, 23 Oct 2024 20:18:45 -0700 Message-ID: <20241024032026.415122-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241024032026.415122-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20241024032026.415122-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The syslog facility property is better handled in lib/log rather than in eal. This also add syslog support to FreeBSD. Signed-off-by: Stephen Hemminger Acked-by: Morten Brørup Acked-by: Bruce Richardson Acked-by: Chengwen Feng --- lib/eal/common/eal_common_options.c | 53 ++-------------- lib/eal/common/eal_internal_cfg.h | 1 - lib/eal/freebsd/eal.c | 5 +- lib/eal/linux/eal.c | 7 +-- lib/eal/windows/eal.c | 6 +- lib/log/log.c | 2 + lib/log/log_freebsd.c | 2 +- lib/log/log_internal.h | 5 +- lib/log/log_linux.c | 61 ------------------ lib/log/log_syslog.c | 98 +++++++++++++++++++++++++++++ lib/log/log_windows.c | 8 ++- lib/log/meson.build | 6 +- lib/log/version.map | 1 + 13 files changed, 130 insertions(+), 125 deletions(-) delete mode 100644 lib/log/log_linux.c create mode 100644 lib/log/log_syslog.c diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index eb079a65a9..71c672e93e 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -6,9 +6,6 @@ #include #include #include -#ifndef RTE_EXEC_ENV_WINDOWS -#include -#endif #include #include #include @@ -93,7 +90,9 @@ eal_long_options[] = { {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM }, {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM }, {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM }, +#ifndef RTE_EXEC_ENV_WINDOWS {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM }, +#endif {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM }, @@ -349,10 +348,6 @@ eal_reset_internal_config(struct internal_config *internal_cfg) } internal_cfg->base_virtaddr = 0; -#ifdef LOG_DAEMON - internal_cfg->syslog_facility = LOG_DAEMON; -#endif - /* if set to NONE, interrupt mode is determined automatically */ internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE; memset(internal_cfg->vfio_vf_token, 0, @@ -1297,47 +1292,6 @@ eal_parse_lcores(const char *lcores) return ret; } -#ifndef RTE_EXEC_ENV_WINDOWS -static int -eal_parse_syslog(const char *facility, struct internal_config *conf) -{ - int i; - static const struct { - const char *name; - int value; - } map[] = { - { "auth", LOG_AUTH }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "kern", LOG_KERN }, - { "lpr", LOG_LPR }, - { "mail", LOG_MAIL }, - { "news", LOG_NEWS }, - { "syslog", LOG_SYSLOG }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, - { NULL, 0 } - }; - - for (i = 0; map[i].name; i++) { - if (!strcmp(facility, map[i].name)) { - conf->syslog_facility = map[i].value; - return 0; - } - } - return -1; -} -#endif - static void eal_log_usage(void) { @@ -1663,6 +1617,7 @@ eal_log_level_parse(int argc, char * const argv[]) switch (opt) { case OPT_LOG_LEVEL_NUM: + case OPT_SYSLOG_NUM: if (eal_parse_common_option(opt, optarg, internal_conf) < 0) return -1; break; @@ -1877,7 +1832,7 @@ eal_parse_common_option(int opt, const char *optarg, #ifndef RTE_EXEC_ENV_WINDOWS case OPT_SYSLOG_NUM: - if (eal_parse_syslog(optarg, conf) < 0) { + if (eal_log_syslog(optarg) < 0) { EAL_LOG(ERR, "invalid parameters for --" OPT_SYSLOG); return -1; diff --git a/lib/eal/common/eal_internal_cfg.h b/lib/eal/common/eal_internal_cfg.h index 167ec501fa..f53ab8b4aa 100644 --- a/lib/eal/common/eal_internal_cfg.h +++ b/lib/eal/common/eal_internal_cfg.h @@ -84,7 +84,6 @@ struct internal_config { /**< true if storing all pages within single files (per-page-size, * per-node) non-legacy mode only. */ - volatile int syslog_facility; /**< facility passed to openlog() */ /** default interrupt mode for VFIO */ volatile enum rte_intr_mode vfio_intr_mode; /** the shared VF token for VFIO-PCI bound PF and VFs devices */ diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 7b974608e4..a609d40ee0 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -392,8 +391,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_LOG_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index c53a051405..9a0a1cf211 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -610,8 +610,8 @@ eal_parse_args(int argc, char **argv) goto out; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -1103,8 +1103,7 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name, - internal_conf->syslog_facility) < 0) { + if (eal_log_init(program_invocation_short_name) < 0) { rte_eal_init_alert("Cannot init logging."); rte_errno = ENOMEM; rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed); diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 93f099a968..cd8420a82c 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -120,8 +120,8 @@ eal_parse_args(int argc, char **argv) return -1; } - /* eal_log_level_parse() already handled this option */ - if (opt == OPT_LOG_LEVEL_NUM) + /* eal_log_level_parse() already handled these options */ + if (opt == OPT_LOG_LEVEL_NUM || opt == OPT_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -249,7 +249,7 @@ rte_eal_init(int argc, char **argv) char cpuset[RTE_CPU_AFFINITY_STR_LEN]; char thread_name[RTE_THREAD_NAME_SIZE]; - eal_log_init(NULL, 0); + eal_log_init(NULL); eal_log_level_parse(argc, argv); diff --git a/lib/log/log.c b/lib/log/log.c index 7416c82b34..d41ca2ed31 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -2,6 +2,7 @@ * Copyright(c) 2010-2014 Intel Corporation */ +#include #include #include #include @@ -12,6 +13,7 @@ #include #include +#include #include #include #ifdef RTE_EXEC_ENV_WINDOWS diff --git a/lib/log/log_freebsd.c b/lib/log/log_freebsd.c index 698d3c5423..953e371bee 100644 --- a/lib/log/log_freebsd.c +++ b/lib/log/log_freebsd.c @@ -6,7 +6,7 @@ #include "log_internal.h" int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) +eal_log_init(__rte_unused const char *id) { return 0; } diff --git a/lib/log/log_internal.h b/lib/log/log_internal.h index 451629f1c1..cb15cdff08 100644 --- a/lib/log/log_internal.h +++ b/lib/log/log_internal.h @@ -14,7 +14,7 @@ * Initialize the default log stream. */ __rte_internal -int eal_log_init(const char *id, int facility); +int eal_log_init(const char *id); /* * Determine where log data is written when no call to rte_openlog_stream. @@ -30,6 +30,9 @@ int eal_log_save_regexp(const char *regexp, uint32_t level); __rte_internal int eal_log_save_pattern(const char *pattern, uint32_t level); +__rte_internal +int eal_log_syslog(const char *name); + /* * Convert log level to string. */ diff --git a/lib/log/log_linux.c b/lib/log/log_linux.c deleted file mode 100644 index 2dfb0c974b..0000000000 --- a/lib/log/log_linux.c +++ /dev/null @@ -1,61 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2010-2014 Intel Corporation - */ - -#include -#include -#include - -#include - -#include "log_internal.h" - -/* - * default log function - */ -static ssize_t -console_log_write(__rte_unused void *c, const char *buf, size_t size) -{ - ssize_t ret; - - /* write on stderr */ - ret = fwrite(buf, 1, size, stderr); - fflush(stderr); - - /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ - syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); - - return ret; -} - -static int -console_log_close(__rte_unused void *c) -{ - closelog(); - return 0; -} - -static cookie_io_functions_t console_log_func = { - .write = console_log_write, - .close = console_log_close, -}; - -/* - * set the log to default function, called during eal init process, - * once memzones are available. - */ -int -eal_log_init(const char *id, int facility) -{ - FILE *log_stream; - - log_stream = fopencookie(NULL, "w+", console_log_func); - if (log_stream == NULL) - return -1; - - openlog(id, LOG_NDELAY | LOG_PID, facility); - - eal_log_set_default(log_stream); - - return 0; -} diff --git a/lib/log/log_syslog.c b/lib/log/log_syslog.c new file mode 100644 index 0000000000..c1f25d2686 --- /dev/null +++ b/lib/log/log_syslog.c @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2014 Intel Corporation + */ + +#include +#include +#include +#include + +#include +#include + +#include "log_internal.h" + +static int log_facility = LOG_DAEMON; + +static const struct { + const char *name; + int value; +} facilitys[] = { + { "auth", LOG_AUTH }, + { "cron", LOG_CRON }, + { "daemon", LOG_DAEMON }, + { "ftp", LOG_FTP }, + { "kern", LOG_KERN }, + { "lpr", LOG_LPR }, + { "mail", LOG_MAIL }, + { "news", LOG_NEWS }, + { "syslog", LOG_SYSLOG }, + { "user", LOG_USER }, + { "uucp", LOG_UUCP }, + { "local0", LOG_LOCAL0 }, + { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, + { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, + { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, + { "local7", LOG_LOCAL7 }, +}; + +int +eal_log_syslog(const char *name) +{ + unsigned int i; + + for (i = 0; i < RTE_DIM(facilitys); i++) { + if (!strcmp(name, facilitys[i].name)) { + log_facility = facilitys[i].value; + return 0; + } + } + return -1; +} + +/* + * default log function + */ +static ssize_t +log_syslog_write(__rte_unused void *c, const char *buf, size_t size) +{ + /* Syslog error levels are from 0 to 7, so subtract 1 to convert */ + syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf); + + return size; +} + +static int +log_syslog_close(__rte_unused void *c) +{ + closelog(); + return 0; +} + +static cookie_io_functions_t log_syslog_func = { + .write = log_syslog_write, + .close = log_syslog_close, +}; + +/* + * set the log to default function, called during eal init process, + * once memzones are available. + */ +int +eal_log_init(const char *id) +{ + FILE *log_stream; + + log_stream = fopencookie(NULL, "w+", log_syslog_func); + if (log_stream == NULL) + return -1; + + openlog(id, LOG_NDELAY | LOG_PID | LOG_PERROR, log_facility); + + eal_log_set_default(log_stream); + + return 0; +} diff --git a/lib/log/log_windows.c b/lib/log/log_windows.c index a6a0889550..a3a756351d 100644 --- a/lib/log/log_windows.c +++ b/lib/log/log_windows.c @@ -6,9 +6,15 @@ #include #include "log_internal.h" +int +eal_log_syslog(const char *name __rte_unused) +{ + return -1; /* not used */ +} + /* set the log to default function, called during eal init process. */ int -eal_log_init(__rte_unused const char *id, __rte_unused int facility) +eal_log_init(__rte_unused const char *id) { rte_openlog_stream(stderr); diff --git a/lib/log/meson.build b/lib/log/meson.build index 0d4319b36f..160cf34f50 100644 --- a/lib/log/meson.build +++ b/lib/log/meson.build @@ -4,6 +4,10 @@ includes += global_inc sources = files( 'log.c', - 'log_' + exec_env + '.c', ) + +if not is_windows + sources += files('log_syslog.c') +endif + headers = files('rte_log.h') diff --git a/lib/log/version.map b/lib/log/version.map index 19d7f9cdb6..879567ba15 100644 --- a/lib/log/version.map +++ b/lib/log/version.map @@ -30,5 +30,6 @@ INTERNAL { eal_log_save_pattern; eal_log_save_regexp; eal_log_set_default; + eal_log_syslog; rte_eal_log_cleanup; }; -- 2.45.2