lib/process: Cleanup stdout callback
authorGeoff Levand <geoff@infradead.org>
Thu, 2 Aug 2018 17:29:35 +0000 (17:29 +0000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 7 Aug 2018 01:30:36 +0000 (11:30 +1000)
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>
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/paths.c
lib/process/process.c
lib/process/process.h

index e30f0320c1f19d5e9e6d5b436ae48ee008f794d4..54b843e77ce3d8df07bdf2df906c6c1231f327bc 100644 (file)
@@ -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 */
index 1fa0bb0dd347aafa48f4844ed00d15487dacd9bb..bc392dc779510245a315c0061b4a14f5d3c06f24 100644 (file)
@@ -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);
index 4904ffc8f5126977f1407bcb8d08703ea5b57037..003ff8ed1329d282942b03bc7a56962d683e4192 100644 (file)
@@ -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 */