diff mbox

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

Message ID 1388344983-19235-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Dec. 29, 2013, 7:23 p.m. UTC
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(+)

Comments

Keng-Yu Lin Jan. 2, 2014, 6:02 a.m. UTC | #1
On Mon, Dec 30, 2013 at 3:23 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_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>
Ivan Hu Jan. 2, 2014, 7:40 a.m. UTC | #2
On 12/30/2013 03:23 AM, Colin King 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_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;
> +}
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

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