diff mbox series

[V2,10/11] swupdate-progress: parse if reboot is disabled

Message ID 20231017140657.95860-11-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series Handle Hawkbit action_id and on the fly updates | expand

Commit Message

Stefano Babic Oct. 17, 2023, 2:06 p.m. UTC
The attribute (boolean) "reboot" can be set in sw-description to disable
a reboot for a single update. This information is just sent via the
progress interface into the info message.

Check if "no-reboot" is present and disable a reboot for the running
update.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 tools/swupdate-progress.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
index cba497a7..48a44481 100644
--- a/tools/swupdate-progress.c
+++ b/tools/swupdate-progress.c
@@ -233,6 +233,7 @@  int main(int argc, char **argv)
 	int c;
 	char *script = NULL;
 	bool wait_update = true;
+	bool disable_reboot = false;
 
 	/* Process options with getopt */
 	while ((c = getopt_long(argc, argv, "cwprhs:e:q",
@@ -321,7 +322,11 @@  int main(int argc, char **argv)
 					fprintf(stdout, "LOCAL\n\n");
 					break;
 				}
+				/*
+				 * Reset per update variables
+				 */
 				curstep = 0;
+				disable_reboot = false;
 				wait_update = false;
 			}
 		}
@@ -330,11 +335,30 @@  int main(int argc, char **argv)
 		 * Be sure that string in message are Null terminated
 		 */
 		if (msg.infolen > 0) {
+			char *reboot_mode;
+			int n, cause;
+
 			if (msg.infolen >= sizeof(msg.info) - 1) {
 				msg.infolen = sizeof(msg.info) - 1;
 			}
 			msg.info[msg.infolen] = '\0';
-			fprintf(stdout, "INFO : %s\r", msg.info);
+			fprintf(stdout, "INFO : %s\n", msg.info);
+
+			/*
+			 * Check for no-reboot mode
+			 * Just do a simple parsing for now. If more messages
+			 * will be added, JSON lib should be linked.
+			 */
+			n = sscanf(msg.info, "{\"%d\": { \"reboot-mode\" : \"%m[-a-z]\"}}",
+				   &cause, &reboot_mode);
+			if (n == 2) {
+				if (cause == CAUSE_REBOOT_MODE) {
+					if (!strcmp(reboot_mode, "no-reboot")) {
+						disable_reboot = true;
+					}
+				}
+				free(reboot_mode);
+			}
 		}
 		msg.cur_image[sizeof(msg.cur_image) - 1] = '\0';
 
@@ -391,7 +415,7 @@  int main(int argc, char **argv)
 			if (psplash_ok)
 				psplash_progress(psplash_pipe_path, &msg);
 			psplash_ok = 0;
-			if ((msg.status == SUCCESS) && (msg.cur_step > 0) && opt_r) {
+			if ((msg.status == SUCCESS) && (msg.cur_step > 0) && opt_r && !disable_reboot) {
 				reboot_device();
 			}
 		#else
@@ -420,7 +444,7 @@  int main(int argc, char **argv)
 				if (psplash_ok)
 					psplash_progress(psplash_pipe_path, &msg);
 				psplash_ok = 0;
-				if (opt_r && strcasestr(msg.info, "firmware")) {
+				if (opt_r && !disable_reboot && strcasestr(msg.info, "firmware")) {
 					reboot_device();
 					break;
 				}