[RFC,3/9] lib/process: Add raw stdout mode

Message ID 20170215043541.10204-3-sam@mendozajonas.com
State RFC
Headers show

Commit Message

Samuel Mendoza-Jonas Feb. 15, 2017, 4:35 a.m.
Allow process users to set 'raw_stdout', which if set skips redirecting
and saving output from processes.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
---
 lib/process/process.c | 7 +++++--
 lib/process/process.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

Patch

diff --git a/lib/process/process.c b/lib/process/process.c
index f7e5b8f..c1606a5 100644
--- a/lib/process/process.c
+++ b/lib/process/process.c
@@ -114,7 +114,7 @@  static int process_setup_stdout_pipe(struct process_info *procinfo)
 {
 	int rc;
 
-	if (!procinfo->process.keep_stdout)
+	if (!procinfo->process.keep_stdout || procinfo->process.raw_stdout)
 		return 0;
 
 	procinfo->stdout_buf_len = 4096;
@@ -132,7 +132,7 @@  static int process_setup_stdout_pipe(struct process_info *procinfo)
 
 static void process_setup_stdout_parent(struct process_info *procinfo)
 {
-	if (!procinfo->process.keep_stdout)
+	if (!procinfo->process.keep_stdout || procinfo->process.raw_stdout)
 		return;
 
 	close(procinfo->stdout_pipe[1]);
@@ -142,6 +142,9 @@  static void process_setup_stdout_child(struct process_info *procinfo)
 {
 	int log = fileno(pb_log_get_stream());
 
+	if (procinfo->process.raw_stdout)
+		return;
+
 	if (procinfo->process.keep_stdout)
 		dup2(procinfo->stdout_pipe[1], STDOUT_FILENO);
 	else
diff --git a/lib/process/process.h b/lib/process/process.h
index f858b0e..4904ffc 100644
--- a/lib/process/process.h
+++ b/lib/process/process.h
@@ -33,6 +33,7 @@  struct process {
 	const char		**argv;
 	bool			keep_stdout;
 	bool			add_stderr;
+	bool			raw_stdout;
 	process_exit_cb		exit_cb;
 	void			*data;
 	waiter_cb		stdout_cb;