From 62dc8c0efe1e8acd694b893effd973a295c5b676 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 11 Sep 2019 11:21:59 +0200 Subject: [PATCH] system: sysupgrade: send reply on error MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This provides some meaningful info on why sysupgrade has failed. Signed-off-by: Rafał Miłecki Acked-by: Jo-Philipp Wich --- system.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/system.c b/system.c index 2a5d5bc..4068e64 100644 --- a/system.c +++ b/system.c @@ -508,6 +508,21 @@ static const struct blobmsg_policy sysupgrade_policy[__SYSUPGRADE_MAX] = { [SYSUPGRADE_OPTIONS] = { .name = "options", .type = BLOBMSG_TYPE_TABLE }, }; +static void sysupgrade_error(struct ubus_context *ctx, + struct ubus_request_data *req, + const char *message) +{ + void *c; + + blob_buf_init(&b, 0); + + c = blobmsg_open_table(&b, "error"); + blobmsg_add_string(&b, "message", message); + blobmsg_close_table(&b, c); + + ubus_send_reply(ctx, req, b.head); +} + static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -534,8 +549,10 @@ static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj, if (!tb[SYSUPGRADE_PATH] || !tb[SYSUPGRADE_PREFIX]) return UBUS_STATUS_INVALID_ARGUMENT; - if (validate_firmware_image_call(blobmsg_get_string(tb[SYSUPGRADE_PATH]))) + if (validate_firmware_image_call(blobmsg_get_string(tb[SYSUPGRADE_PATH]))) { + sysupgrade_error(ctx, req, "Firmware image couldn't be validated"); return UBUS_STATUS_UNKNOWN_ERROR; + } blobmsg_parse(validation_policy, __VALIDATION_MAX, validation, blob_data(b.head), blob_len(b.head)); @@ -545,14 +562,14 @@ static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj, if (!valid) { if (!forceable) { - fprintf(stderr, "Firmware image is broken and cannot be installed\n"); + sysupgrade_error(ctx, req, "Firmware image is broken and cannot be installed"); return UBUS_STATUS_NOT_SUPPORTED; } else if (!tb[SYSUPGRADE_FORCE] || !blobmsg_get_bool(tb[SYSUPGRADE_FORCE])) { - fprintf(stderr, "Firmware image is invalid\n"); + sysupgrade_error(ctx, req, "Firmware image is invalid"); return UBUS_STATUS_NOT_SUPPORTED; } } else if (!allow_backup && tb[SYSUPGRADE_BACKUP]) { - fprintf(stderr, "Firmware image doesn't allow preserving a backup\n"); + sysupgrade_error(ctx, req, "Firmware image doesn't allow preserving a backup"); return UBUS_STATUS_NOT_SUPPORTED; } -- 2.25.1