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");
}
argv[1] = path;
+ argv[2] = command;
DEBUG(2, "Exec to upgraded now\n");
if (wdt_fd) {
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;
}
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) {
}
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);