upgraded: add support for passing a "command" argument to stage2
authorMatthias Schiffer <mschiffer@universe-factory.net>
Sun, 23 Apr 2017 17:04:25 +0000 (19:04 +0200)
committerMatthias Schiffer <mschiffer@universe-factory.net>
Mon, 29 May 2017 19:43:55 +0000 (21:43 +0200)
This allows us to make use of upgraded in "snapshot convert" as well.

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
system.c
upgraded/upgraded.c

index 193c9b05afa6ef5a160a1b11633eb4b543b13fe4..69ba57e49db00eb2c2cc44287828c12d52383597 100644 (file)
--- a/system.c
+++ b/system.c
@@ -346,19 +346,21 @@ static int proc_signal(struct ubus_context *ctx, struct ubus_object *obj,
 enum {
        SYSUPGRADE_PATH,
        SYSUPGRADE_PREFIX,
+       SYSUPGRADE_COMMAND,
        __SYSUPGRADE_MAX
 };
 
 static const struct blobmsg_policy sysupgrade_policy[__SYSUPGRADE_MAX] = {
        [SYSUPGRADE_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
        [SYSUPGRADE_PREFIX] = { .name = "prefix", .type = BLOBMSG_TYPE_STRING },
+       [SYSUPGRADE_COMMAND] = { .name = "command", .type = BLOBMSG_TYPE_STRING },
 };
 
 static void
-procd_exec_upgraded(const char *prefix, char *path)
+procd_exec_upgraded(const char *prefix, char *path, char *command)
 {
        char *wdt_fd = watchdog_fd();
-       char *argv[] = { "/sbin/upgraded", NULL, NULL};
+       char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
 
        if (chroot(prefix)) {
                fprintf(stderr, "Failed to chroot for upgraded exec.\n");
@@ -366,6 +368,7 @@ procd_exec_upgraded(const char *prefix, char *path)
        }
 
        argv[1] = path;
+       argv[2] = command;
 
        DEBUG(2, "Exec to upgraded now\n");
        if (wdt_fd) {
@@ -395,7 +398,8 @@ static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj,
                return UBUS_STATUS_INVALID_ARGUMENT;
 
        procd_exec_upgraded(blobmsg_get_string(tb[SYSUPGRADE_PREFIX]),
-                           blobmsg_get_string(tb[SYSUPGRADE_PATH]));
+                           blobmsg_get_string(tb[SYSUPGRADE_PATH]),
+                           tb[SYSUPGRADE_COMMAND] ? blobmsg_get_string(tb[SYSUPGRADE_COMMAND]) : NULL);
        return 0;
 }
 
index aa0b4ffdb218c03b53276263b346c17170ba17d0..303edb7135e2632cf5b67a182212fc6c0391e115 100644 (file)
@@ -39,11 +39,12 @@ static void upgrade_proc_cb(struct uloop_process *proc, int ret)
        uloop_end();
 }
 
-static void sysupgrade(char *folder)
+static void sysupgrade(char *path, char *command)
 {
-       char *args[] = { "/sbin/sysupgrade", "nand", NULL, NULL };
+       char *args[] = { "/sbin/sysupgrade", "nand", NULL, NULL, NULL };
 
-       args[2] = folder;
+       args[2] = path;
+       args[3] = command;
        upgrade_proc.cb = upgrade_proc_cb;
        upgrade_proc.pid = fork();
        if (!upgrade_proc.pid) {
@@ -80,14 +81,14 @@ int main(int argc, char **argv)
        }
        close(fd);
 
-       if (argc != 2) {
-               fprintf(stderr, "sysupgrade stage 2 failed, no folder specified\n");
+       if (argc != 2 && argc != 3) {
+               fprintf(stderr, "sysupgrade stage 2 failed, invalid command line\n");
                return -1;
        }
 
        uloop_init();
        watchdog_init(0);
-       sysupgrade(argv[1]);
+       sysupgrade(argv[1], (argc == 3) ? argv[2] : NULL);
        uloop_run();
 
        reboot(RB_AUTOBOOT);