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

Keng-Yu Lin kengyu at canonical.com
Thu Jan 2 06:02:11 UTC 2014


On Mon, Dec 30, 2013 at 3:23 AM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at 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 at 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_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 at canonical.com>



More information about the fwts-devel mailing list