From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0144.outbound.protection.outlook.com [65.55.169.144]) by dpdk.org (Postfix) with ESMTP id 5EAA48D8A for ; Tue, 13 Oct 2015 19:14:43 +0200 (CEST) Received: from CY1PR0101MB0987.prod.exchangelabs.com (10.160.224.149) by CY1PR0101MB0987.prod.exchangelabs.com (10.160.224.149) with Microsoft SMTP Server (TLS) id 15.1.293.16; Tue, 13 Oct 2015 17:14:39 +0000 Received: from CY1PR0101MB0987.prod.exchangelabs.com ([10.160.224.149]) by CY1PR0101MB0987.prod.exchangelabs.com ([10.160.224.149]) with mapi id 15.01.0293.007; Tue, 13 Oct 2015 17:14:39 +0000 From: Don Provan To: Tiwei Bie , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1 Thread-Index: AQHRBZaShIsSHmJxtkyKmQCqCgDwCZ5pnoZQ Date: Tue, 13 Oct 2015 17:14:38 +0000 Message-ID: References: <1444726446-8106-1-git-send-email-btw@mail.ustc.edu.cn> <1444726446-8106-2-git-send-email-btw@mail.ustc.edu.cn> In-Reply-To: <1444726446-8106-2-git-send-email-btw@mail.ustc.edu.cn> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=dprovan@bivio.net; x-originating-ip: [209.234.132.35] x-microsoft-exchange-diagnostics: 1; CY1PR0101MB0987; 5:YhL56lmBkQ6crOpOJGgRKRCYI/SUWhGRygMQ5QYaH4esRqh+0HQmrkdvP0pCk01vNue93RQwxmqNRx8VFnkvnnqPXItoU2wdbzexxVvhIV9k8+IbS33o1YT8Akj0BNHEtjHwV+6vNUn+N9cW0I71WQ==; 24:E3JId+rgiRF9tyvYeV2L8J4r6SAEZQPvCeuQWQ7TqGWU7jJNz88lL9eOL7VelewRU2dc6mSqAtglgqZYx7gsYXiOjmTJoAOHt/oBkribIfc=; 20:as6M7R9b4eSrZQSvW3xLELllezI0Uxx9Te8tQ1QTWUZZrHD23s3Ayhv97CrVj8ak/Pn6Y8XHfYUaYY90wS8dfg== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0101MB0987; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(2401047)(5005006)(520078)(8121501046)(3002001); SRVR:CY1PR0101MB0987; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0101MB0987; x-forefront-prvs: 07283408BE x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(199003)(189002)(13464003)(377454003)(11100500001)(105586002)(5001960100002)(5003600100002)(5002640100001)(86362001)(106356001)(107886002)(189998001)(5008740100001)(33656002)(106116001)(101416001)(66066001)(54356999)(19580395003)(5004730100002)(64706001)(76176999)(5007970100001)(2171001)(74316001)(2950100001)(50986999)(19580405001)(10400500002)(97736004)(81156007)(46102003)(92566002)(87936001)(40100003)(5001770100001)(2501003)(2900100001)(77096005)(102836002)(122556002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0101MB0987; H:CY1PR0101MB0987.prod.exchangelabs.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:3; LANG:en; received-spf: None (protection.outlook.com: bivio.net does not designate permitted sender hosts) spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: bivio.net X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Oct 2015 17:14:38.4120 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8731bc55-0e76-4eb7-ae4b-401e56037945 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0101MB0987 Subject: Re: [dpdk-dev] [PATCH] eal/bsd: reinitialize optind and optreset to 1 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: Tue, 13 Oct 2015 17:14:43 -0000 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 shoul= d be saving optind (and optarg and optopt) at the beginning, initializing o= ptind to 1 before calling getopt_long(), then restoring all the values afte= r. (And, from what you're saying, optreset should be handled the same as op= tind.) This avoids broken behavior if rte_eal_init() is called by code that's in t= he middle of using getopt() to parse its own unrelated argc/argv parameters= .=20 -don provan dprovan@bivio.net -----Original Message----- From: Tiwei Bie [mailto:btw@mail.ustc.edu.cn]=20 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 a= rgument 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 --- 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/ea= l.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; } =20 - optind =3D 0; /* reset getopt lib */ + optind =3D 1; /* reset getopt lib */ + optreset =3D 1; } =20 /* Parse the argument given in the command line of the application */ @@ -= 403,7 +404,8 @@ eal_parse_args(int argc, char **argv) if (optind >=3D 0) argv[optind-1] =3D prgname; ret =3D optind-1; - optind =3D 0; /* reset getopt lib */ + optind =3D 1; /* reset getopt lib */ + optreset =3D 1; return ret; } =20 -- 2.6.0