We'd like a way to cancel pending loads, as part of aborting the boot
process.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
data = task->async_data;
cb = task->async_cb;
data = task->async_data;
cb = task->async_cb;
- result->status = process->exit_status == 0 ? LOAD_OK : LOAD_ERROR;
- if (result->status == LOAD_ERROR)
+ if (result->status == LOAD_CANCELLED) {
load_url_result_cleanup_local(result);
load_url_result_cleanup_local(result);
+ } else if (process->exit_status == 0) {
+ result->status = LOAD_OK;
+ } else {
+ result->status = LOAD_ERROR;
+ load_url_result_cleanup_local(result);
+ }
/* The load callback may well free the ctx, which was the
* talloc parent of the task. Therefore, we want to do our cleanup
/* The load callback may well free the ctx, which was the
* talloc parent of the task. Therefore, we want to do our cleanup
*/
process_release(process);
talloc_free(task);
*/
process_release(process);
talloc_free(task);
task->url = url;
task->async = async_cb != NULL;
task->result = talloc_zero(ctx, struct load_url_result);
task->url = url;
task->async = async_cb != NULL;
task->result = talloc_zero(ctx, struct load_url_result);
+ task->result->task = task;
task->process = process_create(task);
if (task->async) {
task->async_cb = async_cb;
task->process = process_create(task);
if (task->async) {
task->async_cb = async_cb;
{
return load_url_async(ctx, url, NULL, NULL);
}
{
return load_url_async(ctx, url, NULL, NULL);
}
+
+void load_url_async_cancel(struct load_url_result *res)
+{
+ struct load_task *task = res->task;
+
+ /* the completion callback may have already been called; this clears
+ * res->task */
+ if (!task)
+ return;
+
+ if (res->status == LOAD_CANCELLED)
+ return;
+
+ assert(task->async);
+ assert(task->process);
+
+ res->status = LOAD_CANCELLED;
+ process_stop_async(task->process);
+}
*/
const char *mount_base(void);
*/
const char *mount_base(void);
struct load_url_result {
enum {
struct load_url_result {
enum {
* (sync will see a NULL result) */
LOAD_ASYNC, /* async load still in progress */
* (sync will see a NULL result) */
LOAD_ASYNC, /* async load still in progress */
- const char *local;
- bool cleanup_local;
+ const char *local;
+ bool cleanup_local;
+ struct load_task *task;
};
/* callback type for asynchronous loads. The callback implementation is
};
/* callback type for asynchronous loads. The callback implementation is
struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
load_url_complete complete, void *data);
struct load_url_result *load_url_async(void *ctx, struct pb_url *url,
load_url_complete complete, void *data);
+/* 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);
#endif /* PATHS_H */
struct load_url_result *load_url(void *ctx, struct pb_url *url);
#endif /* PATHS_H */