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" <dev@dpdk.org>, Don Provan <dprovan@bivio.net>
Subject: Re: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1
Date: Wed, 14 Oct 2015 10:31:28 +0100	[thread overview]
Message-ID: <20151014093128.GC32308@bricha3-MOBL3> (raw)
In-Reply-To: <20151014022843.GA26774@dell>

On Wed, Oct 14, 2015 at 10:28:44AM +0800, Tiwei Bie wrote:
> On Tue, Oct 13, 2015 at 05:14:38PM +0000, Don Provan wrote:
> > Actually, this is a good opportunity to fix a bug that's been in this code forever: it shouldn't be resetting optind to some arbitrary value: it should be saving optind (and optarg and optopt) at the beginning, initializing optind to 1 before calling getopt_long(), then restoring all the values after. (And, from what you're saying, optreset should be handled the same as optind.)
> > 
> 
> It is designed to have DPDK's parameters specified in the front of the
> cmd line and terminated by '--'. Or at least, you should put DPDK's
> parameters together and terminate them by '--'. And 1 or 0 are not some
> arbitrary values. They are used to put the index back to the beginning
> of the new argv[] array.
> 
> > This avoids broken behavior if rte_eal_init() is called by code that's in the middle of using getopt() to parse its own unrelated argc/argv parameters. 
> > 
> 
> We shouldn't mix up DPDK's parameters and application's parameters.
> And we should group them using '--'.
> 
> Best,
> Tiwei Bie

While true, that does not prevent us from implementing Don's suggestion, as it
should fix the bug you are looking at with your original patch, and also allow
additional use-cases for applications at no extra cost.

/Bruce

> 
> > -don provan
> > dprovan@bivio.net
> > 
> > -----Original Message-----
> > From: Tiwei Bie [mailto:btw@mail.ustc.edu.cn] 
> > Sent: Tuesday, October 13, 2015 1:54 AM
> > To: dev@dpdk.org
> > Subject: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1
> > 
> > The variable optind must be reinitialized to 1 in order to skip over argv[0] on FreeBSD. Because getopt() on FreeBSD will return -1 when it meets an argument which doesn't start with '-'.
> > 
> > The variable optreset is provided on FreeBSD to indicate the additional set of calls to getopt(). So, also reinitialize it to 1.
> > 
> > Signed-off-by: Tiwei Bie <btw@mail.ustc.edu.cn>
> > ---
> >  lib/librte_eal/bsdapp/eal/eal.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/lib/librte_eal/bsdapp/eal/eal.c b/lib/librte_eal/bsdapp/eal/eal.c index 1b6f705..35feaee 100644
> > --- a/lib/librte_eal/bsdapp/eal/eal.c
> > +++ b/lib/librte_eal/bsdapp/eal/eal.c
> > @@ -334,7 +334,8 @@ eal_log_level_parse(int argc, char **argv)
> >  			break;
> >  	}
> >  
> > -	optind = 0; /* reset getopt lib */
> > +	optind = 1; /* reset getopt lib */
> > +	optreset = 1;
> >  }
> >  
> >  /* Parse the argument given in the command line of the application */ @@ -403,7 +404,8 @@ eal_parse_args(int argc, char **argv)
> >  	if (optind >= 0)
> >  		argv[optind-1] = prgname;
> >  	ret = optind-1;
> > -	optind = 0; /* reset getopt lib */
> > +	optind = 1; /* reset getopt lib */
> > +	optreset = 1;
> >  	return ret;
> >  }
> >  
> > --
> > 2.6.0
> > 
> > 
> > 
> 

  parent reply	other threads:[~2015-10-14  9:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-13  8:54 [dpdk-dev] [PATCH] Found a bug related to getopt() in eal/bsd module Tiwei Bie
2015-10-13  8:54 ` [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1 Tiwei Bie
2015-10-13 14:58   ` Bruce Richardson
2015-10-13 17:14   ` Don Provan
     [not found]     ` <20151014022843.GA26774@dell>
2015-10-14  9:31       ` Bruce Richardson [this message]
2015-10-14 10:19         ` Tiwei Bie
2015-10-14 11:28           ` Tiwei Bie
2015-10-14 17:54             ` Don Provan
2015-10-15  1:40               ` Tiwei Bie

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=20151014093128.GC32308@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).