2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <sys/reboot.h>
24 #include <libubox/uloop.h>
26 #include "../watchdog.h"
29 #define O_PATH 010000000
32 static struct uloop_process upgrade_proc;
33 unsigned int debug = 2;
35 static void upgrade_proc_cb(struct uloop_process *proc, int ret)
38 fprintf(stderr, "sysupgrade aborted with return code: %d\n", ret);
42 static void sysupgrade(char *folder)
44 char *args[] = { "/sbin/sysupgrade", "nand", NULL, NULL };
47 upgrade_proc.cb = upgrade_proc_cb;
48 upgrade_proc.pid = fork();
49 if (!upgrade_proc.pid) {
50 execvp(args[0], args);
51 fprintf(stderr, "Failed to fork sysupgrade\n");
54 if (upgrade_proc.pid <= 0) {
55 fprintf(stderr, "Failed to start sysupgrade\n");
60 int main(int argc, char **argv)
65 fprintf(stderr, "this tool needs to run as pid 1\n");
69 int fd = open("/", O_DIRECTORY|O_PATH);
71 fprintf(stderr, "unable to open prefix directory: %s\n", strerror(errno));
77 if (fchdir(fd) == -1) {
78 fprintf(stderr, "failed to chdir to prefix directory: %s\n", strerror(errno));
84 fprintf(stderr, "sysupgrade stage 2 failed, no folder specified\n");