sysupgrade: support "backup" attribute
authorRafał Miłecki <rafal@milecki.pl>
Wed, 11 Sep 2019 06:58:15 +0000 (08:58 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Wed, 11 Sep 2019 06:58:15 +0000 (08:58 +0200)
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 <rafal@milecki.pl>
initd/preinit.c
system.c
sysupgrade.c
sysupgrade.h

index 2b4df4ba218a359c8c3275ddcdbcde0bad71d47c..84e62b0d4af1179b20f57d6a85b5c92710e9e793 100644 (file)
@@ -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);
index ad24a30a6ce68779e27ab386055b5574e50d9634..98fcb661f4f0a5b1c643cbf4160f1321395847de 100644 (file)
--- 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]);
 
index 19fb05428cb3cc497d6a45063701620f4930aa61..fc588b0248353137d4b81fce130d2d35d8dfa710 100644 (file)
@@ -25,7 +25,8 @@
 
 #include <libubox/blobmsg.h>
 
-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_";
index c84e4945c226678b46d3547c17800fe49d8272f0..268e2fd94421ea19f9511a012a43b53430f6ccb2 100644 (file)
@@ -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);