From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id ED58A8E76 for ; Mon, 19 Oct 2015 12:36:51 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 19 Oct 2015 03:36:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,701,1437462000"; d="scan'208";a="796817873" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.208.63]) by orsmga001.jf.intel.com with SMTP; 19 Oct 2015 03:36:42 -0700 Received: by (sSMTP sendmail emulation); Mon, 19 Oct 2015 11:36:41 +0025 Date: Mon, 19 Oct 2015 11:36:41 +0100 From: Bruce Richardson To: Tiwei Bie Message-ID: <20151019103641.GA13936@bricha3-MOBL3> References: <1444909564-53691-1-git-send-email-btw@mail.ustc.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1444909564-53691-1-git-send-email-btw@mail.ustc.edu.cn> Organization: Intel Shannon Ltd. User-Agent: Mutt/1.5.23 (2014-03-12) Cc: dev@dpdk.org, dprovan@bivio.net Subject: Re: [dpdk-dev] [PATCH] eal: don't reset getopt lib X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2015 10:36:52 -0000 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 > Suggested-by: Bruce Richardson > Signed-off-by: Tiwei Bie > --- > 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;