From: Rafał Miłecki Date: Wed, 11 Sep 2019 09:21:59 +0000 (+0200) Subject: system: sysupgrade: send reply on error X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=62dc8c0efe1e8acd694b893effd973a295c5b676;p=oweals%2Fprocd.git system: sysupgrade: send reply on error This provides some meaningful info on why sysupgrade has failed. Signed-off-by: Rafał Miłecki Acked-by: Jo-Philipp Wich --- 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; }