From patchwork Sun Dec 29 19:21:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 305669 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3D1252C0095 for ; Mon, 30 Dec 2013 06:22:00 +1100 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1VxLvz-0005WC-1a; Sun, 29 Dec 2013 19:21:59 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1VxLvk-0005V8-Oq for fwts-devel@lists.ubuntu.com; Sun, 29 Dec 2013 19:21:44 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginm.net ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1VxLvk-0001SU-MA for fwts-devel@lists.ubuntu.com; Sun, 29 Dec 2013 19:21:44 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/2] lib: add fwts_exec() helper function Date: Sun, 29 Dec 2013 19:21:41 +0000 Message-Id: <1388344902-19151-2-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1388344902-19151-1-git-send-email-colin.king@canonical.com> References: <1388344902-19151-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King fwts_pipe_exec is being frequently in fwts with the output being thrown away because it is not required. Add fwts_exec to do an exec without the need to generate any output that this immediately discarded. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin --- src/lib/include/fwts_pipeio.h | 1 + src/lib/src/fwts_pipeio.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/lib/include/fwts_pipeio.h b/src/lib/include/fwts_pipeio.h index 87cfb61..a6a7aff 100644 --- a/src/lib/include/fwts_pipeio.h +++ b/src/lib/include/fwts_pipeio.h @@ -32,5 +32,6 @@ int fwts_pipe_open(const char *command, pid_t *childpid); char *fwts_pipe_read(const int fd, ssize_t *length); int fwts_pipe_close(const int fd, const pid_t pid); int fwts_pipe_exec(const char *command, fwts_list **list, int *status); +int fwts_exec(const char *command, int *status); #endif diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c index 42a7cb2..4d38ab7 100644 --- a/src/lib/src/fwts_pipeio.c +++ b/src/lib/src/fwts_pipeio.c @@ -158,3 +158,22 @@ int fwts_pipe_exec(const char *command, fwts_list **list, int *status) } return FWTS_OK; } + +/* + * fwts_pipe_exec() + * execute a command + * Return FWTS_OK if the exec worked, FWTS_EXEC_ERROR if + * it failed. status contains the child exit status. + */ +int fwts_exec(const char *command, int *status) +{ + pid_t pid; + int fd; + + if ((fd = fwts_pipe_open(command, &pid)) < 0) + return FWTS_ERROR; + + if (!(*status = fwts_pipe_close(fd, pid))) + return FWTS_EXEC_ERROR; + return FWTS_OK; +}