[PATCH 3/6] discover/paths: Extend load_url_async() to accept stdout callback

Samuel Mendoza-Jonas sam at mendozajonas.com
Tue Oct 25 14:44:45 AEDT 2016


Add an additional parameter to load_url_async() which allows callers to
set a specific callback function to be used by the process IO waiter.

This callback will only have access to the process struct which is
opaque outside of paths.c, so add load_task_async_data() to allow
accessing the task data in the IO callback.

Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
 discover/boot.c       |  2 +-
 discover/paths.c      | 13 +++++++++++--
 discover/paths.h      |  6 +++++-
 discover/pxe-parser.c |  4 ++--
 test/parser/utils.c   |  6 +++++-
 5 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/discover/boot.c b/discover/boot.c
index dc6da7d..e7e4543 100644
--- a/discover/boot.c
+++ b/discover/boot.c
@@ -500,7 +500,7 @@ static int start_url_load(struct boot_task *task, const char *name,
 	if (!url)
 		return 0;
 
-	*result = load_url_async(task, url, boot_process, task);
+	*result = load_url_async(task, url, boot_process, task, NULL);
 	if (!*result) {
 		update_status(task->status_fn, task->status_arg,
 				BOOT_STATUS_ERROR,
diff --git a/discover/paths.c b/discover/paths.c
index 7fcff9e..e2213a0 100644
--- a/discover/paths.c
+++ b/discover/paths.c
@@ -28,6 +28,13 @@ struct load_task {
 	void			*async_data;
 };
 
+void *load_task_async_data(struct process *process)
+{
+	struct load_task *task = process->data;
+
+	return task ? task->async_data : NULL;
+}
+
 const char *mount_base(void)
 {
 	return DEVICE_MOUNT_BASE;
@@ -370,7 +377,8 @@ static void load_local(struct load_task *task)
  */
 
 struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
-		load_url_complete async_cb, void *async_data)
+		load_url_complete async_cb, void *async_data,
+		waiter_cb stdout_cb)
 {
 	struct load_url_result *result;
 	struct load_task *task;
@@ -389,6 +397,7 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
 		task->async_data = async_data;
 		task->process->exit_cb = load_url_process_exit;
 		task->process->data = task;
+		task->process->custom_stdout_cb = stdout_cb;
 	}
 
 	switch (url->scheme) {
@@ -429,7 +438,7 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
 
 struct load_url_result *load_url(void *ctx, struct pb_url *url)
 {
-	return load_url_async(ctx, url, NULL, NULL);
+	return load_url_async(ctx, url, NULL, NULL, NULL);
 }
 
 void load_url_async_cancel(struct load_url_result *res)
diff --git a/discover/paths.h b/discover/paths.h
index ed0e153..5af6bb8 100644
--- a/discover/paths.h
+++ b/discover/paths.h
@@ -2,6 +2,8 @@
 #define PATHS_H
 
 #include <url/url.h>
+#include <waiter/waiter.h>
+#include <process/process.h>
 
 /**
  * Utility function for joining two paths. Adds a / between a and b if
@@ -42,11 +44,13 @@ typedef void (*load_url_complete)(struct load_url_result *result, void *data);
 
 /* Load a (potentially remote) file, and return a guaranteed-local name */
 struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
-		load_url_complete complete, void *data);
+		load_url_complete complete, void *data,
+		waiter_cb stdout_cb);
 
 /* Cancel a pending load */
 void load_url_async_cancel(struct load_url_result *res);
 
 struct load_url_result *load_url(void *ctx, struct pb_url *url);
+void *load_task_async_data(struct process *process);
 
 #endif /* PATHS_H */
diff --git a/discover/pxe-parser.c b/discover/pxe-parser.c
index 4352036..d216280 100644
--- a/discover/pxe-parser.c
+++ b/discover/pxe-parser.c
@@ -225,7 +225,7 @@ static void pxe_load_next_filename(struct conf_context *conf)
 		if (!url)
 			continue;
 
-		if (load_url_async(conf, url, pxe_conf_parse_cb, conf))
+		if (load_url_async(conf, url, pxe_conf_parse_cb, conf, NULL))
 			break;
 	}
 
@@ -365,7 +365,7 @@ static int pxe_parse(struct discover_context *dc)
 	if (complete_url) {
 		/* we have a complete URL; use this and we're done. */
 		result = load_url_async(conf->dc, conf->dc->conf_url,
-					pxe_conf_parse_cb, conf);
+					pxe_conf_parse_cb, conf, NULL);
 		if (!result) {
 			pb_log("load_url_async fails for %s\n",
 					dc->conf_url->path);
diff --git a/test/parser/utils.c b/test/parser/utils.c
index f0796fd..6635074 100644
--- a/test/parser/utils.c
+++ b/test/parser/utils.c
@@ -309,7 +309,8 @@ int parser_replace_file(struct discover_context *ctx,
 }
 
 struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
-		load_url_complete async_cb, void *async_data)
+		load_url_complete async_cb, void *async_data,
+		waiter_cb stdout_cb)
 {
 	struct conf_context *conf = async_data;
 	struct parser_test *test = conf->dc->test_data;
@@ -319,6 +320,9 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
 	struct test_file *file;
 	int fd;
 
+	/* Ignore the stdout callback for tests */
+	(void)stdout_cb;
+
 	fd = mkstemp(tmp);
 
 	if (fd < 0)
-- 
2.10.0



More information about the Petitboot mailing list