On 2024/9/18 12:56, Stephen Hemminger wrote: > The code to parse for log-level option should be same on > all OS variants. > > Signed-off-by: Stephen Hemminger <step...@networkplumber.org> > Acked-by: Tyler Retzlaff <roret...@linux.microsoft.com> > Acked-by: Morten Brørup <m...@smartsharesystems.com> > --- > 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 f1a5e329a5..b0ceeef632 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;
no need goto, could use break > + 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; > +} > + ...