From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ustc.edu.cn (smtp2.ustc.edu.cn [202.38.64.46]) by dpdk.org (Postfix) with ESMTP id 977B38DA6 for ; Tue, 13 Oct 2015 10:55:10 +0200 (CEST) Received: from dell.my.domain (unknown [222.195.92.204]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygBnVwjlxhxWjcmpAQ--.37974S2; Tue, 13 Oct 2015 16:55:05 +0800 (CST) From: Tiwei Bie To: dev@dpdk.org Date: Tue, 13 Oct 2015 16:54:05 +0800 Message-Id: <1444726446-8106-1-git-send-email-btw@mail.ustc.edu.cn> X-Mailer: git-send-email 2.6.0 X-CM-TRANSID: LkAmygBnVwjlxhxWjcmpAQ--.37974S2 X-Coremail-Antispam: 1UD129KBjvJXoWxJrWxAF1xCryDCw1ftr18Zrb_yoW8Gr43pa 9ruFnxJF18J3yIv39Yga18KFySvrWDJFy8Crn8J34DAw1fKF1kWw4YyrWrtF47uFZ3CayY vr1kZan8uF1akrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkIb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8ZwCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jr0_JrylIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvE x4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU5ZL07UUUUU== X-CM-SenderInfo: xewzqzxdloh3xvwfhvlgxou0/1tbiAQcBAVQhmEeO0gAGs2 Subject: [dpdk-dev] [PATCH] Found a bug related to getopt() in eal/bsd module 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 08:55:11 -0000 I found a bug when trying to make my DPDK application work on FreeBSD. The variable optind must be reinitialized to 1 on FreeBSD to skip over argv[0]. Because getopt() on FreeBSD will return -1 when it meets an argument which doesn't start with '-'. This behaviour is implemented by the 13-17 lines: 01 /* 02 * getopt -- 03 * Parse argc/argv argument vector. 04 */ 05 int 06 getopt(int nargc, char * const nargv[], const char *ostr) 07 { 08 static char *place = EMSG; /* option letter processing */ 09 char *oli; /* option letter list index */ 10 11 if (optreset || *place == 0) { /* update scanning pointer */ 12 optreset = 0; 13 place = nargv[optind]; 14 if (optind >= nargc || *place++ != '-') { 15 /* Argument is absent or is not an option */ 16 place = EMSG; 17 return (-1); 18 } 19 ...... 20 } 21 ...... 22 } The variable optreset is also provided on FreeBSD to indicate the additional set of calls to getopt(). So, also reinitialize it to 1. References: 1. https://svnweb.freebsd.org/base/head/lib/libc/stdlib/getopt.c?view=markup#l70 2. https://www.freebsd.org/cgi/man.cgi?query=getopt&apropos=0&sektion=3&manpath=FreeBSD+11-current&arch=default&format=html Tiwei Bie (1): eal/bsd: reinitialize optind and optreset to 1 lib/librte_eal/bsdapp/eal/eal.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) -- 2.6.0