From 5918b6d3c38dea4c9cdbc229d34494e4185aa2b3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 23 Apr 2017 19:04:25 +0200 Subject: [PATCH] upgraded: add support for passing a "command" argument to stage2 This allows us to make use of upgraded in "snapshot convert" as well. Signed-off-by: Matthias Schiffer --- system.c | 10 +++++++--- upgraded/upgraded.c | 13 +++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/system.c b/system.c index 193c9b0..69ba57e 100644 --- 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; } diff --git a/upgraded/upgraded.c b/upgraded/upgraded.c index aa0b4ff..303edb7 100644 --- a/upgraded/upgraded.c +++ b/upgraded/upgraded.c @@ -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); -- 2.25.1