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 B4DF691EF for ; Fri, 16 Oct 2015 04:25:51 +0200 (CEST) Received: from dell (unknown [222.195.92.204]) by newmailweb.ustc.edu.cn (Coremail) with SMTP id LkAmygAX+sIkYCBWowS_AQ--.40466S2; Fri, 16 Oct 2015 10:25:48 +0800 (CST) Date: Fri, 16 Oct 2015 10:25:29 +0800 From: Tiwei Bie To: Don Provan Message-ID: <20151016022529.GA9234@dell> References: <1444909564-53691-1-git-send-email-btw@mail.ustc.edu.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-CM-TRANSID: LkAmygAX+sIkYCBWowS_AQ--.40466S2 X-Coremail-Antispam: 1UD129KBjvJXoWxuw15ur4rKr1UJr1fKFW3KFg_yoW3Wr18pr W3G3WY9r1xtrWxKw42qa1kGF4Fkws7t3WUC3yxZayFywsIg34kGa4UKFsxuF13Grs8JrW8 XF4FvF4j9Fy5K3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk0b7Iv0xC_KF4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcVAKI48JMxkIecxEwVAFwVW8JwCF04k20xvY 0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I 0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jrv_JF1lIxkGc2Ij64vIr41lIxAI cVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcV CF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280 aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxUcBT5DUUUU X-CM-SenderInfo: xewzqzxdloh3xvwfhvlgxou0/1tbiAQcEAVQhmEjhfQAEs+ Cc: "dev@dpdk.org" 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: Fri, 16 Oct 2015 02:25:53 -0000 On Thu, Oct 15, 2015 at 04:22:53PM +0000, Don Provan wrote: > Looks perfect. Thanks! Thanks! It's my pleasure. :-) Best wishes, Tiwei Bie > -don > > -----Original Message----- > From: Tiwei Bie [mailto:btw@mail.ustc.edu.cn] > Sent: Thursday, October 15, 2015 4:46 AM > To: Don Provan ; bruce.richardson@intel.com; dev@dpdk.org > Subject: [PATCH] eal: don't reset getopt lib > > 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. > > 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; > > argvopt = argv; > + optind = 1; > + optreset = 1; > > eal_reset_internal_config(&internal_config); > > @@ -334,7 +346,11 @@ eal_log_level_parse(int argc, char **argv) > break; > } > > - optind = 0; /* reset getopt lib */ > + /* restore getopt lib */ > + optind = old_optind; > + optopt = old_optopt; > + optreset = old_optreset; > + optarg = old_optarg; > } > > /* Parse the argument given in the command line of the application */ @@ -345,25 +361,37 @@ eal_parse_args(int argc, char **argv) > char **argvopt; > int option_index; > char *prgname = argv[0]; > + 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; > > argvopt = argv; > + optind = 1; > + optreset = 1; > > while ((opt = getopt_long(argc, argvopt, eal_short_options, > eal_long_options, &option_index)) != EOF) { > > - int ret; > - > /* getopt is not happy, stop right now */ > if (opt == '?') { > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > > ret = eal_parse_common_option(opt, optarg, &internal_config); > /* common parser is not happy */ > if (ret < 0) { > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > /* common parser handled this option */ > if (ret == 0) > @@ -387,23 +415,34 @@ eal_parse_args(int argc, char **argv) > "on FreeBSD\n", opt); > } > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > } > > - if (eal_adjust_config(&internal_config) != 0) > - return -1; > + if (eal_adjust_config(&internal_config) != 0) { > + ret = -1; > + goto out; > + } > > /* sanity checks */ > if (eal_check_common_options(&internal_config) != 0) { > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > > if (optind >= 0) > argv[optind-1] = prgname; > ret = optind-1; > - optind = 0; /* reset getopt lib */ > + > +out: > + /* restore getopt lib */ > + optind = old_optind; > + optopt = old_optopt; > + optreset = old_optreset; > + optarg = old_optarg; > + > return ret; > } > > diff --git a/lib/librte_eal/linuxapp/eal/eal.c b/lib/librte_eal/linuxapp/eal/eal.c > index 33e1067..4796030 100644 > --- a/lib/librte_eal/linuxapp/eal/eal.c > +++ b/lib/librte_eal/linuxapp/eal/eal.c > @@ -505,8 +505,17 @@ eal_log_level_parse(int argc, char **argv) > int opt; > char **argvopt; > int option_index; > + int old_optind; > + int old_optopt; > + char *old_optarg; > + > + /* save getopt lib */ > + old_optind = optind; > + old_optopt = optopt; > + old_optarg = optarg; > > argvopt = argv; > + optind = 1; > > eal_reset_internal_config(&internal_config); > > @@ -527,7 +536,10 @@ eal_log_level_parse(int argc, char **argv) > break; > } > > - optind = 0; /* reset getopt lib */ > + /* restore getopt lib */ > + optind = old_optind; > + optopt = old_optopt; > + optarg = old_optarg; > } > > /* Parse the argument given in the command line of the application */ @@ -539,25 +551,34 @@ eal_parse_args(int argc, char **argv) > int option_index; > char *prgname = argv[0]; > struct shared_driver *solib; > + int old_optind; > + int old_optopt; > + char *old_optarg; > + > + /* save getopt lib */ > + old_optind = optind; > + old_optopt = optopt; > + old_optarg = optarg; > > argvopt = argv; > + optind = 1; > > while ((opt = getopt_long(argc, argvopt, eal_short_options, > eal_long_options, &option_index)) != EOF) { > > - int ret; > - > /* getopt is not happy, stop right now */ > if (opt == '?') { > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > > ret = eal_parse_common_option(opt, optarg, &internal_config); > /* common parser is not happy */ > if (ret < 0) { > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > /* common parser handled this option */ > if (ret == 0) > @@ -573,7 +594,8 @@ eal_parse_args(int argc, char **argv) > solib = malloc(sizeof(*solib)); > if (solib == NULL) { > RTE_LOG(ERR, EAL, "malloc(solib) failed\n"); > - return -1; > + ret = -1; > + goto out; > } > memset(solib, 0, sizeof(*solib)); > strncpy(solib->name, optarg, PATH_MAX-1); @@ -589,7 +611,8 @@ eal_parse_args(int argc, char **argv) > RTE_LOG(ERR, EAL, "Can't support DPDK app " > "running on Dom0, please configure" > " RTE_LIBRTE_XEN_DOM0=y\n"); > - return -1; > + ret = -1; > + goto out; > #endif > break; > > @@ -606,7 +629,8 @@ eal_parse_args(int argc, char **argv) > RTE_LOG(ERR, EAL, "invalid parameters for --" > OPT_SOCKET_MEM "\n"); > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > break; > > @@ -615,7 +639,8 @@ eal_parse_args(int argc, char **argv) > RTE_LOG(ERR, EAL, "invalid parameter for --" > OPT_BASE_VIRTADDR "\n"); > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > break; > > @@ -624,7 +649,8 @@ eal_parse_args(int argc, char **argv) > RTE_LOG(ERR, EAL, "invalid parameters for --" > OPT_VFIO_INTR "\n"); > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > break; > > @@ -646,17 +672,21 @@ eal_parse_args(int argc, char **argv) > "on Linux\n", opt); > } > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > } > > - if (eal_adjust_config(&internal_config) != 0) > - return -1; > + if (eal_adjust_config(&internal_config) != 0) { > + ret = -1; > + goto out; > + } > > /* sanity checks */ > if (eal_check_common_options(&internal_config) != 0) { > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > > /* --xen-dom0 doesn't make sense with --socket-mem */ @@ -664,13 +694,20 @@ eal_parse_args(int argc, char **argv) > RTE_LOG(ERR, EAL, "Options --"OPT_SOCKET_MEM" cannot be specified " > "together with --"OPT_XEN_DOM0"\n"); > eal_usage(prgname); > - return -1; > + ret = -1; > + goto out; > } > > if (optind >= 0) > argv[optind-1] = prgname; > ret = optind-1; > - optind = 0; /* reset getopt lib */ > + > +out: > + /* restore getopt lib */ > + optind = old_optind; > + optopt = old_optopt; > + optarg = old_optarg; > + > return ret; > } > > -- > 2.1.2 > >