From b8238df0fb9585b5ec9acbc0f4285dad953f2192 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 11 Sep 2019 08:58:15 +0200 Subject: [PATCH] sysupgrade: support "backup" attribute MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This new attribute allows passing path of the backup archive. It provides much more flexibility than hardcoding /tmp/sysupgrade.tgz. It may help avoiding some cp/mv for user-provided backup archive. Signed-off-by: Rafał Miłecki --- initd/preinit.c | 2 +- system.c | 3 +++ sysupgrade.c | 6 ++++-- sysupgrade.h | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/initd/preinit.c b/initd/preinit.c index 2b4df4b..84e62b0 100644 --- a/initd/preinit.c +++ b/initd/preinit.c @@ -75,7 +75,7 @@ check_sysupgrade(void) fclose(sysupgrade); - sysupgrade_exec_upgraded(prefix, path, command, NULL); + sysupgrade_exec_upgraded(prefix, path, NULL, command, NULL); while (true) sleep(1); diff --git a/system.c b/system.c index ad24a30..98fcb66 100644 --- a/system.c +++ b/system.c @@ -492,6 +492,7 @@ static int validate_firmware_image(struct ubus_context *ctx, enum { SYSUPGRADE_PATH, SYSUPGRADE_FORCE, + SYSUPGRADE_BACKUP, SYSUPGRADE_PREFIX, SYSUPGRADE_COMMAND, SYSUPGRADE_OPTIONS, @@ -501,6 +502,7 @@ enum { static const struct blobmsg_policy sysupgrade_policy[__SYSUPGRADE_MAX] = { [SYSUPGRADE_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING }, [SYSUPGRADE_FORCE] = { .name = "force", .type = BLOBMSG_TYPE_BOOL }, + [SYSUPGRADE_BACKUP] = { .name = "backup", .type = BLOBMSG_TYPE_STRING }, [SYSUPGRADE_PREFIX] = { .name = "prefix", .type = BLOBMSG_TYPE_STRING }, [SYSUPGRADE_COMMAND] = { .name = "command", .type = BLOBMSG_TYPE_STRING }, [SYSUPGRADE_OPTIONS] = { .name = "options", .type = BLOBMSG_TYPE_TABLE }, @@ -550,6 +552,7 @@ static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj, sysupgrade_exec_upgraded(blobmsg_get_string(tb[SYSUPGRADE_PREFIX]), blobmsg_get_string(tb[SYSUPGRADE_PATH]), + tb[SYSUPGRADE_BACKUP] ? blobmsg_get_string(tb[SYSUPGRADE_BACKUP]) : NULL, tb[SYSUPGRADE_COMMAND] ? blobmsg_get_string(tb[SYSUPGRADE_COMMAND]) : NULL, tb[SYSUPGRADE_OPTIONS]); diff --git a/sysupgrade.c b/sysupgrade.c index 19fb054..fc588b0 100644 --- a/sysupgrade.c +++ b/sysupgrade.c @@ -25,7 +25,8 @@ #include -void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command, +void sysupgrade_exec_upgraded(const char *prefix, char *path, + const char *backup, char *command, struct blob_attr *options) { char *wdt_fd = watchdog_fd(); @@ -48,7 +49,8 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command, setenv("WDTFD", wdt_fd, 1); } - setenv("UPGRADE_BACKUP", "/tmp/sysupgrade.tgz", 1); + if (backup) + setenv("UPGRADE_BACKUP", backup, 1); blobmsg_for_each_attr(option, options, rem) { const char *prefix = "UPGRADE_OPT_"; diff --git a/sysupgrade.h b/sysupgrade.h index c84e494..268e2fd 100644 --- a/sysupgrade.h +++ b/sysupgrade.h @@ -16,7 +16,8 @@ struct blob_attr; -void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command, +void sysupgrade_exec_upgraded(const char *prefix, char *path, + const char *backup, char *command, struct blob_attr *options); -- 2.25.1