diff mbox series

Do not traces messages for progress interface

Message ID 20200302095322.26516-1-sbabic@denx.de
State Accepted
Headers show
Series Do not traces messages for progress interface | expand

Commit Message

Stefano Babic March 2, 2020, 9:53 a.m. UTC
During downloading a TRACE is sent to the notifier with the goal to
forward it to the progress interface. However, as TRACE, this is also
shown and processed by all notifier causing an overflood of messages on
the console that cna slow down the system.

Move this to a separate notifier and drop it from console notifier.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/notifier.c           | 24 ++++++++++++++++++++++++
 corelib/channel_curl.c    |  2 +-
 include/swupdate_status.h |  1 +
 3 files changed, 26 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/core/notifier.c b/core/notifier.c
index 8643c6f..3dbc382 100644
--- a/core/notifier.c
+++ b/core/notifier.c
@@ -143,6 +143,13 @@  static void console_notifier (RECOVERY_STATUS status, int error, int level, cons
 	case SUBPROCESS:
 		snprintf(current, sizeof(current), "EVENT [%d] : ", error );
 		break;
+	/*
+	 * PROGRESS is a special case. It is used for subprocesses to send
+	 * progress information via the notifier. A trace with this status
+	 * is processed by the progress notifier
+	 */
+	case PROGRESS:
+		return;
 	case DONE:
 		strncpy(current, "SWUPDATE done : ", sizeof(current));
 		break;
@@ -203,6 +210,22 @@  static void process_notifier (RECOVERY_STATUS status, int event, int level, cons
 
 }
 
+/*
+ * Progress notifier: the message should be forwarded to the progress
+ * interface only.
+ */
+static void progress_notifier (RECOVERY_STATUS status, int event, int level, const char *msg)
+{
+	(void)level;
+
+	/* Check just in case a process want to send an info outside */
+	if (status != PROGRESS)
+	       return;
+
+	swupdate_progress_info(status, event, msg);
+}
+
+
 #if defined(__FreeBSD__)
 static char* socket_path = NULL;
 static void unlink_socket(void)
@@ -365,6 +388,7 @@  void notify_init(void)
 		STAILQ_INIT(&clients);
 		register_notifier(console_notifier);
 		register_notifier(process_notifier);
+		register_notifier(progress_notifier);
 		start_thread(notifier_thread, NULL);
 	}
 }
diff --git a/corelib/channel_curl.c b/corelib/channel_curl.c
index c00e994..d7ca1eb 100644
--- a/corelib/channel_curl.c
+++ b/corelib/channel_curl.c
@@ -381,7 +381,7 @@  static int channel_callback_xferinfo(void *p, curl_off_t dltotal, curl_off_t dln
 					"{\"percent\": %d, \"msg\":\"Received %" CURL_FORMAT_CURL_OFF_T "B "
 					"of %" CURL_FORMAT_CURL_OFF_T "B\"}",
 					(int)percent, dlnow, dltotal) != ENOMEM_ASPRINTF) {
-		notify(SUBPROCESS, RECOVERY_NO_ERROR, TRACELEVEL, info);
+		notify(PROGRESS, RECOVERY_NO_ERROR, TRACELEVEL, info);
 		free(info);
 	}
 	return 0;
diff --git a/include/swupdate_status.h b/include/swupdate_status.h
index 38811e3..8ac9af1 100644
--- a/include/swupdate_status.h
+++ b/include/swupdate_status.h
@@ -27,6 +27,7 @@  typedef enum {
 	DOWNLOAD,
 	DONE,
 	SUBPROCESS,
+	PROGRESS,
 } RECOVERY_STATUS;
 
 typedef enum {