From patchwork Wed May 11 16:41:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 67558 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp293458qge; Wed, 11 May 2016 08:45:17 -0700 (PDT) X-Received: by 10.140.129.17 with SMTP id 17mr4380243qhb.91.1462981517026; Wed, 11 May 2016 08:45:17 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id a190si5593673qke.76.2016.05.11.08.45.16; Wed, 11 May 2016 08:45:17 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id A142B616B0; Wed, 11 May 2016 15:45:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 7DB3B6164A; Wed, 11 May 2016 15:44:13 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2A83A61606; Wed, 11 May 2016 15:44:09 +0000 (UTC) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by lists.linaro.org (Postfix) with ESMTPS id 3C94161606 for ; Wed, 11 May 2016 15:44:08 +0000 (UTC) Received: by mail-lf0-f41.google.com with SMTP id y84so54197817lfc.0 for ; Wed, 11 May 2016 08:44:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Sknax+z3utoOZEfybkvMI4MTnggBL5SYqn9jxsYRFrA=; b=Ou4YgY1xhe84psoxD043gaWRwQsU0h7jXboWUYnSFwPOyCgQp/75dcqJkzmnSeI2Ql 1t0liL8TqHRlQBc+fNANFd1vtZ991obhhd7gssz75IbWYwgxhtJwQoSSww6BC0sQ+GoM HZDehwrwbxsMOiXNgfclC3Fhh0JvLcAPRYKrSJ4rAH0TmlbNi7wY8ooUVzLG/t75U9lX NhJj1cVRKeLcH193vvTSLp5yZkDDWeEZn9WZC/hpcM/NB0Z/wx/nzhl0mWsUlnVUTLnu s0vF6IWRVAgdrqkpzi5eXp/tTiRvkF/EawWbP/Nx6oFWkObse4KjnG/xnXwp7aeXZ7fh AOXw== X-Gm-Message-State: AOPr4FWN8Ip6ViUPRxHu0XXxTAdiEYMKyXcSwFCQxgDPdFkqzIR7e6cfDiBOci8rr3/fLVNyWLQ= X-Received: by 10.25.170.140 with SMTP id t134mr1947271lfe.17.1462981447102; Wed, 11 May 2016 08:44:07 -0700 (PDT) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id n37sm1421164lfg.46.2016.05.11.08.44.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 May 2016 08:44:06 -0700 (PDT) From: Christophe Milard To: brian.brooks@linaro.org, mike.holmes@linaro.org, lng-odp@lists.linaro.org Date: Wed, 11 May 2016 18:41:45 +0200 Message-Id: <1462984942-53326-2-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1462984942-53326-1-git-send-email-christophe.milard@linaro.org> References: <1462984942-53326-1-git-send-email-christophe.milard@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv6 01/38] helpers: adding command line argument parsing X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" A function to parse options meant for the helpers out of a the command line is added. This parse function picks up options altering the behaviour of the helpers out of the command line. Other options are reject. No helper options are definied (yet). Signed-off-by: Christophe Milard --- helper/include/odp/helper/linux.h | 13 +++++++++++++ helper/linux.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/helper/include/odp/helper/linux.h b/helper/include/odp/helper/linux.h index 7a6504f..c6736a0 100644 --- a/helper/include/odp/helper/linux.h +++ b/helper/include/odp/helper/linux.h @@ -130,6 +130,19 @@ int odph_linux_process_fork_n(odph_linux_process_t *proc_tbl, int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num); +/** + * Parse linux helper options + * + * Parse the command line options. Pick up options meant for the helper itself. + * + * @param argc argument count + * @param argv argument values + * + * @return On success: 0 + * On failure: -1 (failure occurs only if a value passed for a helper + * option is invalid. callers cannot have own options) + */ +int odph_parse_options(int argc, char *argv[]); #ifdef __cplusplus } #endif diff --git a/helper/linux.c b/helper/linux.c index 24e243b..5dbc2da 100644 --- a/helper/linux.c +++ b/helper/linux.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -236,3 +237,32 @@ int odph_linux_process_wait_n(odph_linux_process_t *proc_tbl, int num) return 0; } + +/* + * Parse command line options to extract options affecting helpers. + */ +int odph_parse_options(int argc, char *argv[]) +{ + int c; + + static struct option long_options[] = { + /* These options set a flag. */ + {0, 0, 0, 0} + }; + + while (1) { + /* getopt_long stores the option index here. */ + int option_index = 0; + + c = getopt_long (argc, argv, "", + long_options, &option_index); + + /* Detect the end of the options. */ + if (c == -1) + break; + } + + optind = 0; /* caller expects this to be zero if it parses too*/ + + return 0; +}