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 96EFA44136; Tue, 4 Jun 2024 02:48:17 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 060B4432B6; Tue, 4 Jun 2024 02:47:52 +0200 (CEST) Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by mails.dpdk.org (Postfix) with ESMTP id 32571432B6 for ; Tue, 4 Jun 2024 02:47:48 +0200 (CEST) Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1f63642ab8aso28315645ad.3 for ; Mon, 03 Jun 2024 17:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1717462067; x=1718066867; 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=MLEJI4gnceGIj2YyD1hlsfBc43bplpy8j7YtBwv/Iuo=; b=MpXGl4W4RhoItR8aUn3DeX/rHZHa/PxHMoXz8HvZpEuF7+JL02hf1n6yULywDdqqxn bceXMCbXiI95RKTRyu/XtCjCQiDqBX2RtmykKOzqhSho6WBzrXKnmqpiP7UWsJ3/ADxk Jr5v5J8dqDBWJ7fF4Neh+k5rmAndrjfq9MsdWdG+VHrKtqvzvnVopCxLDEpaIXobgMzi L1UtqYh25H2y2Pkn0uEPJQ1VK2yfVz03Ty0aQT+mlE1kaaZMFGCm6BEwgZOgySH1ZNZN qFHkzORP1VA21EiuHm17SvC1sd/jtnJglXAKAseQh/F0ZrxHauHkDmNiTq8vIsKFzNXZ U1UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717462067; x=1718066867; 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=MLEJI4gnceGIj2YyD1hlsfBc43bplpy8j7YtBwv/Iuo=; b=g2S/KQp48JTErRfaJJ4jBpRMusBsSQnfkKdS8gFeCJwqsjL95MqNPsbcbSLd6qr/J9 p9EViT8f+9ZMar1xnpAZ9IRGBbBP3q+5Bu97KLmjYQpl7U2fzaOIN+vkLJqXKwcc5igV gAucPdfMl5ScHgSUbQDd4jRlQ7SAbfgxn6pAFGavJ7WmHi2PYsWSp4BZmYelTFXGHBVk jCDOH85qO151JbcZ9FmusgXdbeevRLPUy7T6q3TBnMf/1ItEoyAl+3PxykOVRIMH5zb2 BdjeyG0dgtcQwQggauI2TG4S7HrKi+24YNNUcj7rhp8p1lH7nA2jSWQuveWk6YfK52kJ Ee3A== X-Gm-Message-State: AOJu0YwpTT1q9ICC6HHxhcF/Rr0S4NiDks23iSQzFr0Zboe8bv6kliad icDAwVlQcCWaSKdo1qS8WMU6qZ3Nm2NU9n9A3+dStaDIfSjEo82DBeCae4jr+Y7BgZWuJGU/Sgu GBOo= X-Google-Smtp-Source: AGHT+IGI5T9cGOn1vGz+/CxuOS9ufVR4OUXZs/nhoaTZxlX2RNOYVJ2YISTxwsaK54W1SBF1nxcf2Q== X-Received: by 2002:a17:902:cf10:b0:1f6:1a86:37e6 with SMTP id d9443c01a7336-1f63701eba7mr121442125ad.23.1717462067261; Mon, 03 Jun 2024 17:47:47 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f6323e9aa7sm70381125ad.192.2024.06.03.17.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 17:47:46 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Bruce Richardson , Dmitry Kozlyuk , Pallavi Kadam Subject: [PATCH v21 04/14] eal: make eal_log_level_parse common Date: Mon, 3 Jun 2024 17:44:52 -0700 Message-ID: <20240604004731.6654-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240604004731.6654-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240604004731.6654-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 code to parse for log-level option should be same on all OS variants. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/eal/common/eal_common_options.c | 45 +++++++++++++++++++++++++++++ lib/eal/common/eal_options.h | 1 + lib/eal/freebsd/eal.c | 42 --------------------------- lib/eal/linux/eal.c | 39 ------------------------- lib/eal/windows/eal.c | 35 ---------------------- 5 files changed, 46 insertions(+), 116 deletions(-) diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c index e541f07939..cb3c52c67a 100644 --- a/lib/eal/common/eal_common_options.c +++ b/lib/eal/common/eal_common_options.c @@ -1640,6 +1640,51 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) return -1; } +/* Parse the all arguments looking for log related ones */ +int +eal_log_level_parse(int argc, char * const argv[]) +{ + struct internal_config *internal_conf = eal_get_internal_configuration(); + int option_index, opt; + const int old_optind = optind; + const int old_optopt = optopt; + const int old_opterr = opterr; + char *old_optarg = optarg; +#ifdef RTE_EXEC_ENV_FREEBSD + const int old_optreset = optreset; + optreset = 1; +#endif + + optind = 1; + opterr = 0; + + while ((opt = getopt_long(argc, argv, eal_short_options, + eal_long_options, &option_index)) != EOF) { + + switch (opt) { + case OPT_LOG_LEVEL_NUM: + if (eal_parse_common_option(opt, optarg, internal_conf) < 0) + return -1; + break; + case '?': + /* getopt is not happy, stop right now */ + goto out; + default: + continue; + } + } +out: + /* restore getopt lib */ + optind = old_optind; + optopt = old_optopt; + optarg = old_optarg; + opterr = old_opterr; +#ifdef RTE_EXEC_ENV_FREEBSD + optreset = old_optreset; +#endif + return 0; +} + int eal_parse_common_option(int opt, const char *optarg, struct internal_config *conf) diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h index 3cc9cb6412..f3f2e104f6 100644 --- a/lib/eal/common/eal_options.h +++ b/lib/eal/common/eal_options.h @@ -96,6 +96,7 @@ enum { extern const char eal_short_options[]; extern const struct option eal_long_options[]; +int eal_log_level_parse(int argc, char * const argv[]); int eal_parse_common_option(int opt, const char *argv, struct internal_config *conf); int eal_option_device_parse(void); diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c index bab77118e9..9825bcea0b 100644 --- a/lib/eal/freebsd/eal.c +++ b/lib/eal/freebsd/eal.c @@ -363,48 +363,6 @@ eal_get_hugepage_mem_size(void) return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - const int old_optreset = optreset; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - optreset = 1; - - 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) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optreset = old_optreset; - optarg = old_optarg; -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index fd422f1f62..bffeb1f34e 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -546,45 +546,6 @@ eal_parse_vfio_vf_token(const char *vf_token) return -1; } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - const int old_optind = optind; - const int old_optopt = optopt; - char * const old_optarg = optarg; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - optind = 1; - - 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) - break; - } - - /* restore getopt lib */ - optind = old_optind; - optopt = old_optopt; - optarg = old_optarg; -} - static int eal_parse_huge_worker_stack(const char *arg) { diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 52f0e7462d..85171b2768 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -96,41 +96,6 @@ eal_usage(const char *prgname) } } -/* Parse the arguments for --log-level only */ -static void -eal_log_level_parse(int argc, char **argv) -{ - int opt; - char **argvopt; - int option_index; - struct internal_config *internal_conf = - eal_get_internal_configuration(); - - argvopt = argv; - - eal_reset_internal_config(internal_conf); - - 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) - break; - } - - optind = 0; /* reset getopt lib */ -} - /* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) -- 2.43.0