Patchwork [1/2] lib: add fwts_exec() helper function

login
register
mail settings
Submitter Colin King
Date Dec. 29, 2013, 7:21 p.m.
Message ID <1388344902-19151-2-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/305669/
State Rejected
Headers show

Comments

Colin King - Dec. 29, 2013, 7:21 p.m.
From: Colin Ian King <colin.king@canonical.com>

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 <colin.king@canonical.com>
---
 src/lib/include/fwts_pipeio.h |  1 +
 src/lib/src/fwts_pipeio.c     | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
Keng-Yu Lin - Jan. 2, 2014, 6 a.m.
On Mon, Dec 30, 2013 at 3:21 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> 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 <colin.king@canonical.com>
> ---
>  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;
> +}
> --
> 1.8.5.2
>

Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

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;
+}