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 820D642D5F; Mon, 26 Jun 2023 20:43:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C012B42D1D; Mon, 26 Jun 2023 20:42:58 +0200 (CEST) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by mails.dpdk.org (Postfix) with ESMTP id 9952D42C4D for ; Mon, 26 Jun 2023 20:42:55 +0200 (CEST) Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-54f85f8b961so2840900a12.3 for ; Mon, 26 Jun 2023 11:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20221208.gappssmtp.com; s=20221208; t=1687804974; x=1690396974; 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=G3wxp+uVKXBcYiMtKKmQyWepL34iCxOs75msWyk+ksk=; b=z4kmpef8ME/v3cMQPod8ra85iuV+CAJD2XOORPyNUchRPkp6j5KSIrqLkr4Aj+aFUJ avy1+MCk9ChMDkbUaQ5D5t99zVqAaXhejL07Agb/G4Sz6nWlZ3v4BiMIpqOiOcKPfVP3 jCBDwyTpzQywCGtuL2FmN0tQGthdkr70e1zVe4vw37efM6eUkxYzFhXbXKoT4AFujA9V wEtybrrYOPAZQZDzoBxmz4ZKEjCONn1Z9C8d/K3nCaURzrigvMp/zRpR8w37Q1ASC63i QsJgNe3QGLK/anWwTnji0lcSIlTinxr3lQZq1bSqvKyGhRGjiti3clAo7cRW27soSN8x +frw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687804974; x=1690396974; 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=G3wxp+uVKXBcYiMtKKmQyWepL34iCxOs75msWyk+ksk=; b=JZKLtGy2r2RF8csOmUgWtmjCISRWiXNBf0hwTj5MJ1RB7RwLctXyyIQpPu5gYXp1E8 x+rl7JBmVSG15Ta7oZJC8yJXQotXbToxsNV6Fh6VDAPiSenv7SAjZQ00M2+wJGxqxVi1 yIv3nl4CNQukWVworVo+rUQAzEkL9QHKrM73DheK3S0V8jLzkzW47SsTUv7l0WTrXoC7 +0FXEt6JesoW/E7lUAwBRGWeb94cpfAfAmHGAtIFZPfDfowos5X/N1SBQTE4ucNGN3rc vXRHEwX7IB2ihhFixYkz4Ck5hpZxyaUm3R/7QYqXQeD0PBolnaULqgVIej4xHNURb4kk xw3A== X-Gm-Message-State: AC+VfDwdkXyUHE0ERQTzl1HhU9q2cRHZuvyRyJIsj8eHICjMqAtiUVME f96y2J8XkeiYdkitR2n8eGp/tt76haac0uOkuigq5w== X-Google-Smtp-Source: ACHHUZ7Xts+0xG/tmxgoblotXY3UuPnSUWSouyGu7W8AQclVOeHQams8VaXQ21IETKK8AXpQYqR1LQ== X-Received: by 2002:a17:90a:190f:b0:258:9995:91cb with SMTP id 15-20020a17090a190f00b00258999591cbmr25158687pjg.49.1687804974487; Mon, 26 Jun 2023 11:42:54 -0700 (PDT) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id h17-20020a17090adb9100b0024e37e0a67dsm4846577pjv.20.2023.06.26.11.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 11:42:54 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v4 4/5] eal: move logging initialization earlier Date: Mon, 26 Jun 2023 11:42:15 -0700 Message-Id: <20230626184223.155390-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230626184223.155390-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20230626184223.155390-1-stephen@networkplumber.org> MIME-Version: 1.0 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 log stream should be setup before any messages. This ensures that any startup problems are captured on the syslog output, not only shown on the stderr. Signed-off-by: Stephen Hemminger --- lib/eal/freebsd/eal.c | 40 +++++++++++++++++++-------------------- lib/eal/linux/eal.c | 44 +++++++++++++++++++++---------------------- 2 files changed, 40 insertions(+), 44 deletions(-) diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index 70087837da18..d3aac3d628a8 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -364,7 +364,7 @@ eal_get_hugepage_mem_size(void) return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX; } -/* Parse the arguments for --log-level only */ +/* Parse the arguments for --log-level and --syslog */ static void eal_log_level_parse(int argc, char **argv) { @@ -386,20 +386,18 @@ eal_log_level_parse(int argc, char **argv) while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) + switch (opt) { + case OPT_SYSLOG_NUM: /* fallthrough */ + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + goto error; break; + case '?': + /* getopt is not happy, stop right now */ + goto error; + } } - +error: /* restore getopt lib */ optind = old_optind; optopt = old_optopt; @@ -437,8 +435,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_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -615,6 +613,12 @@ rte_eal_init(int argc, char **argv) /* set log level as early as possible */ eal_log_level_parse(argc, argv); + if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + return -1; + } + if (rte_eal_cpu_init() < 0) { rte_eal_init_alert("Cannot detect lcores."); rte_errno = ENOTSUP; @@ -762,12 +766,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(getprogname(), internal_conf->syslog_facility) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - return -1; - } - /* in secondary processes, memory init may allocate additional fbarrays * not present in primary processes, so to avoid any potential issues, * initialize memzones first. diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 60bb130aea15..51c4ec75d57b 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -546,7 +546,7 @@ eal_parse_vfio_vf_token(const char *vf_token) return -1; } -/* Parse the arguments for --log-level only */ +/* Parse the arguments for --log-level and --syslog */ static void eal_log_level_parse(int argc, char **argv) { @@ -566,20 +566,18 @@ eal_log_level_parse(int argc, char **argv) while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { - int ret; - - /* getopt is not happy, stop right now */ - if (opt == '?') - break; - - ret = (opt == OPT_LOG_LEVEL_NUM) ? - eal_parse_common_option(opt, optarg, internal_conf) : 0; - - /* common parser is not happy */ - if (ret < 0) + switch (opt) { + case OPT_SYSLOG_NUM: /* fallthrough */ + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + goto error; break; + case '?': + /* getopt is not happy, stop right now */ + goto error; + } } - +error: /* restore getopt lib */ optind = old_optind; optopt = old_optopt; @@ -651,8 +649,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_SYSLOG_NUM) continue; ret = eal_parse_common_option(opt, optarg, internal_conf); @@ -997,6 +995,14 @@ rte_eal_init(int argc, char **argv) /* set log level as early as possible */ eal_log_level_parse(argc, argv); + if (eal_log_init(program_invocation_short_name, + internal_conf->syslog_facility) < 0) { + rte_eal_init_alert("Cannot init logging."); + rte_errno = ENOMEM; + __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); + return -1; + } + /* clone argv to report out later in telemetry */ eal_save_args(argc, argv); @@ -1167,14 +1173,6 @@ rte_eal_init(int argc, char **argv) #endif } - if (eal_log_init(program_invocation_short_name, - internal_conf->syslog_facility) < 0) { - rte_eal_init_alert("Cannot init logging."); - rte_errno = ENOMEM; - __atomic_store_n(&run_once, 0, __ATOMIC_RELAXED); - return -1; - } - #ifdef VFIO_PRESENT if (rte_eal_vfio_setup() < 0) { rte_eal_init_alert("Cannot init VFIO"); -- 2.39.2