[LEDE-DEV] [PATCH v2 05/19] procd: upgraded: add support for passing a "command" argument to stage2

Matthias Schiffer mschiffer at universe-factory.net
Sat May 13 12:56:35 PDT 2017


This allows us to make use of upgraded in "snapshot convert" as well.

Signed-off-by: Matthias Schiffer <mschiffer at universe-factory.net>

Note: obviously, this patch should go into the procd repo when it is
actually applied; it is provided like this for now to allow easier testing
of the whole series.
---
 ...d-support-for-passing-a-command-argument-.patch | 104 +++++++++++++++++++++
 1 file changed, 104 insertions(+)
 create mode 100644 package/system/procd/patches/0003-upgraded-add-support-for-passing-a-command-argument-.patch

diff --git a/package/system/procd/patches/0003-upgraded-add-support-for-passing-a-command-argument-.patch b/package/system/procd/patches/0003-upgraded-add-support-for-passing-a-command-argument-.patch
new file mode 100644
index 0000000000..2a5b258608
--- /dev/null
+++ b/package/system/procd/patches/0003-upgraded-add-support-for-passing-a-command-argument-.patch
@@ -0,0 +1,104 @@
+From a90626d588abf71426f57513174427b0bf8feeab Mon Sep 17 00:00:00 2001
+Message-Id: <a90626d588abf71426f57513174427b0bf8feeab.1493040735.git.mschiffer at universe-factory.net>
+In-Reply-To: <3462ccc0c91964ec92c1c61cde803a6504b2fb24.1493040735.git.mschiffer at universe-factory.net>
+References: <3462ccc0c91964ec92c1c61cde803a6504b2fb24.1493040735.git.mschiffer at universe-factory.net>
+From: Matthias Schiffer <mschiffer at universe-factory.net>
+Date: Sun, 23 Apr 2017 19:04:25 +0200
+Subject: [PATCH 3/5] 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 <mschiffer at universe-factory.net>
+---
+ 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.12.2
+
-- 
2.13.0




More information about the Lede-dev mailing list