Browse Source

sysupgrade: support "backup" attribute

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>
Rafał Miłecki 4 years ago
parent
commit
b8238df0fb
4 changed files with 10 additions and 4 deletions
  1. 1 1
      initd/preinit.c
  2. 3 0
      system.c
  3. 4 2
      sysupgrade.c
  4. 2 1
      sysupgrade.h

+ 1 - 1
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);

+ 3 - 0
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]);
 

+ 4 - 2
sysupgrade.c

@@ -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_";

+ 2 - 1
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);