DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: Tiwei Bie <btw@mail.ustc.edu.cn>
Cc: dev@dpdk.org, dprovan@bivio.net
Subject: Re: [dpdk-dev] [PATCH] eal: don't reset getopt lib
Date: Mon, 19 Oct 2015 11:36:41 +0100	[thread overview]
Message-ID: <20151019103641.GA13936@bricha3-MOBL3> (raw)
In-Reply-To: <1444909564-53691-1-git-send-email-btw@mail.ustc.edu.cn>

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@bivio.net>
> Suggested-by: Bruce Richardson <bruce.richardson@intel.com>
> Signed-off-by: Tiwei Bie <btw@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>

  parent reply	other threads:[~2015-10-19 10:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-15 11:46 Tiwei Bie
2015-10-15 16:22 ` Don Provan
2015-10-16  2:25   ` Tiwei Bie
2015-10-19 10:36 ` Bruce Richardson [this message]
2015-10-19 13:15   ` Tiwei Bie
2015-10-19 13:13 ` [dpdk-dev] [PATCH v2] " Tiwei Bie
2015-10-19 13:16   ` Bruce Richardson
2015-10-21  5:33     ` David Marchand
2015-10-21  6:17       ` Tiwei Bie
2015-11-04 22:21       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151019103641.GA13936@bricha3-MOBL3 \
    --to=bruce.richardson@intel.com \
    --cc=btw@mail.ustc.edu.cn \
    --cc=dev@dpdk.org \
    --cc=dprovan@bivio.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).