[dpdk-dev] [PATCH] eal: don't reset getopt lib

Bruce Richardson bruce.richardson at intel.com
Mon Oct 19 12:36:41 CEST 2015


On Thu, Oct 15, 2015 at 07:46:04PM +0800, Tiwei Bie wrote:
> Someone may need to call rte_eal_init() with a fake argc/argv array
> in the middle of using getopt() to parse its own unrelated argc/argv
> parameters. So getopt lib shouldn't be reset by rte_eal_init().
> 
> Now eal will always save optind, optarg and optopt (and optreset on
> FreeBSD) at the beginning, initialize optind (and optreset on FreeBSD)
> to 1 before calling getopt_long(), then restore all values after.

This patch looks good overall. Minor comment inline below.

/Bruce
> 
> Suggested-by: Don Provan <dprovan at bivio.net>
> Suggested-by: Bruce Richardson <bruce.richardson at intel.com>
> Signed-off-by: Tiwei Bie <btw at mail.ustc.edu.cn>
> ---
>  lib/librte_eal/bsdapp/eal/eal.c   | 59 +++++++++++++++++++++++++++------
>  lib/librte_eal/linuxapp/eal/eal.c | 69 ++++++++++++++++++++++++++++++---------
>  2 files changed, 102 insertions(+), 26 deletions(-)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c
> index 1b6f705..bd09377 100644
> --- a/lib/librte_eal/bsdapp/eal/eal.c
> +++ b/lib/librte_eal/bsdapp/eal/eal.c
> @@ -312,8 +312,20 @@ eal_log_level_parse(int argc, char **argv)
>  	int opt;
>  	char **argvopt;
>  	int option_index;
> +	int old_optind;
> +	int old_optopt;
> +	int old_optreset;
> +	char *old_optarg;
> +
> +	/* save getopt lib */
> +	old_optind = optind;
> +	old_optopt = optopt;
> +	old_optreset = optreset;
> +	old_optarg = optarg;

Rather than adding in 10 lines, you could shorten this, and provide additional
compiler hints by merging these assignments into the variable declarations, and
then making the vars const. e.g.

	const int old_optind = optind;

>  
>  	argvopt = argv;
> +	optind = 1;
> +	optreset = 1;
<snip>


More information about the dev mailing list