diff mbox series

[v2,12/30] lib/process: Cleanup stdout callback

Message ID ec8eb018fcca757ed238b45750cb6deadff7a4aa.1533230644.git.geoff@infradead.org
State Accepted
Headers show
Series [v2,01/30] docker: Add libfdt-dev | expand

Commit Message

Geoff Levand Aug. 2, 2018, 5:29 p.m. UTC
General cleanup of async stdout processing.

The process_stdout_cb and process_stdout_custom routines were doing the
same thing, so rename process_stdout_custom to process_process_stdout
and make process_stdout_cb a wrapper that calls process_process_stdout.

Signed-off-by: Geoff Levand <geoff@infradead.org>
---
 discover/paths.c      |  2 +-
 lib/process/process.c | 32 ++++++++------------------------
 lib/process/process.h |  2 +-
 3 files changed, 10 insertions(+), 26 deletions(-)
diff mbox series

Patch

diff --git a/discover/paths.c b/discover/paths.c
index 174bdae..dc654bd 100644
--- a/discover/paths.c
+++ b/discover/paths.c
@@ -158,7 +158,7 @@  static int busybox_progress_cb(void *arg)
 	p = procinfo_get_process(procinfo);
 	handler = p->stdout_data;
 
-	rc = process_stdout_custom(procinfo, &line);
+	rc = process_process_stdout(procinfo, &line);
 
 	if (rc) {
 		/* Unregister ourselves from progress tracking */
diff --git a/lib/process/process.c b/lib/process/process.c
index 1fa0bb0..bc392dc 100644
--- a/lib/process/process.c
+++ b/lib/process/process.c
@@ -178,28 +178,7 @@  static int process_read_stdout(struct process_info *procinfo)
 	return rc < 0 ? rc : 0;
 }
 
-static int process_stdout_cb(void *arg)
-{
-	struct process_info *procinfo = arg;
-	int rc;
-
-	rc = process_read_stdout_once(procinfo, NULL);
-
-	/* if we're going to signal to the waitset that we're done (ie, non-zero
-	 * return value), then the waiters will remove us, so we drop the
-	 * reference */
-	if (rc < 0) {
-		talloc_unlink(procset, procinfo);
-		procinfo->stdout_waiter = NULL;
-		rc = -1;
-	} else {
-		rc = 0;
-	}
-
-	return rc;
-}
-
-int process_stdout_custom(struct process_info *procinfo, char **line)
+int process_process_stdout(struct process_info *procinfo, char **line)
 {
 	int rc;
 
@@ -417,10 +396,14 @@  int process_run_sync(struct process *process)
 	return 0;
 }
 
+static int process_stdout_cb(struct process_info *procinfo)
+{
+	return process_process_stdout(procinfo, NULL);
+}
+
 int process_run_async(struct process *process)
 {
 	struct process_info *procinfo = get_info(process);
-	waiter_cb stdout_cb;
 	int rc;
 
 	rc = process_run_common(procinfo);
@@ -428,7 +411,8 @@  int process_run_async(struct process *process)
 		return rc;
 
 	if (process->keep_stdout) {
-		stdout_cb = process->stdout_cb ?: process_stdout_cb;
+		waiter_cb stdout_cb = process->stdout_cb ?:
+			(waiter_cb)process_stdout_cb;
 		procinfo->stdout_waiter = waiter_register_io(procset->waitset,
 						procinfo->stdout_pipe[0],
 						WAIT_IN, stdout_cb, procinfo);
diff --git a/lib/process/process.h b/lib/process/process.h
index 4904ffc..003ff8e 100644
--- a/lib/process/process.h
+++ b/lib/process/process.h
@@ -87,6 +87,6 @@  bool process_exit_ok(struct process *process);
 
 /* Functions to assist callers using a custom stdout callback */
 struct process *procinfo_get_process(struct process_info *procinfo);
-int process_stdout_custom(struct process_info *procinfo, char **line);
+int process_process_stdout(struct process_info *procinfo, char **line);
 
 #endif /* PROCESS_H */