From d3bc159bf8dcb5e170659739a028b8df1dc121a8 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 29 Jul 2021 23:52:34 +0200 Subject: [PATCH] autoupdater: verify the image before upgrading Let sysupgrade run a --test upgrade to verify that the image is compatible before attempting an upgrade. This fixes an issue where a router can get stuck without network connectivity when a a remote autoupgrade was triggered. Fixes #193 --- admin/autoupdater/src/autoupdater.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/admin/autoupdater/src/autoupdater.c b/admin/autoupdater/src/autoupdater.c index 0b80c07..dcf8829 100644 --- a/admin/autoupdater/src/autoupdater.c +++ b/admin/autoupdater/src/autoupdater.c @@ -378,6 +378,22 @@ static bool autoupdate(const char *mirror, struct settings *s, int lock_fd) { } } + /* Test the image upgrade (issue #193) */ + { + static const char *const test_option = " --test "; + + char buf[strlen(sysupgrade_path) + strlen(test_option) + strlen(firmware_path) + 1]; + strcpy(buf, sysupgrade_path); + strcat(buf, test_option); + strcat(buf, firmware_path); + + const int sysupgrade_ret = system(buf); + if (WEXITSTATUS(sysupgrade_ret) != 0 ) { + fprintf(stderr, "autoupdater: warning: sysupgrade --test failed with return code: %d\n", WEXITSTATUS(sysupgrade_ret)); + goto fail_after_download; + } + } + clear_manifest(m); /**** Call sysupgrade ************************************************/