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

Colin King colin.king at canonical.com
Sun Dec 29 19:21:41 UTC 2013


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_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




More information about the fwts-devel mailing list