From d977e40b11d2febec0f96f794ca27f4ece2b42af Mon Sep 17 00:00:00 2001 From: Adrian DC Date: Sat, 2 Nov 2024 22:38:12 +0100 Subject: [PATCH] mongoose, progress: resolve 'Restart System' from web UI IPC event If 'swupdate-progress' service is used with its '-r' reboot mode, and if 'globals : { postupdatecmd = "/sbin/reboot"; };' is not used, the 'Restart System' button on the SWUpdate web UI has no effect. An IPC event 'DONE' is sent upon '/restart' endpoint event, however the 'swupdate-progress' only prints a log without rebooting. Add a specific message info to request a reboot through IPC 'DONE'. --- Signed-off-by: Adrian DC --- mongoose/mongoose_interface.c | 8 ++++++-- tools/swupdate-progress.c | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c index 1d636cdf..98639a35 100644 --- a/mongoose/mongoose_interface.c +++ b/mongoose/mongoose_interface.c @@ -344,8 +344,12 @@ static const char *get_source_string(unsigned int source) static void restart_handler(struct mg_connection *nc, void *ev_data) { - struct mg_http_message *hm = (struct mg_http_message *) ev_data; - ipc_message msg = {}; + struct mg_http_message* hm = (struct mg_http_message*)ev_data; + ipc_message msg; + + size_t size = sizeof(msg.data.procmsg.buf); + snprintf(msg.data.procmsg.buf, size, "{\"reboot\": \"true\"}"); + msg.data.procmsg.len = strnlen(msg.data.procmsg.buf, size); if(mg_strcasecmp(hm->method, mg_str("POST")) != 0) { mg_http_reply(nc, 405, "", "%s", "Method Not Allowed\n"); diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c index 5e371627..6b70546e 100644 --- a/tools/swupdate-progress.c +++ b/tools/swupdate-progress.c @@ -442,6 +442,9 @@ int main(int argc, char **argv) break; case DONE: fprintf(stdout, "\nDONE.\n\n"); + if (opt_r && strcasestr(msg.info, "\"reboot\": \"true\"")) { + reboot_device(); + } break; case PROGRESS: /*