diff mbox series

[1/1] network_thread: break out of the case on the notification history

Message ID 20230524210650.17186-1-charles.hardin@chargepoint.com
State Accepted
Delegated to: Stefano Babic
Headers show
Series [1/1] network_thread: break out of the case on the notification history | expand

Commit Message

Charles Hardin May 24, 2023, 9:06 p.m. UTC
There is a loop to send the notification history on the control
socket and if there was an error in that loop, then the code
would just continue with an unlocked mutex and progressing into
the control path. This error path seems to be very rare (if ever)
and so unlikely to be hit in any testing without some external
conditions shutting down sockets.

Signed-off-by: Charles Hardin <charles.hardin@chargepoint.com>
---
 core/network_thread.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/core/network_thread.c b/core/network_thread.c
index f4ee335..c8a0d39 100644
--- a/core/network_thread.c
+++ b/core/network_thread.c
@@ -611,11 +611,9 @@  void *network_thread (void *data)
 					break;
 				}
 
-				/* Get first notification from the queue */
-				pthread_mutex_lock(&msglock);
-				notification = SIMPLEQ_FIRST(&notifymsgs);
-
 				/* Send notify history */
+				pthread_mutex_lock(&msglock);
+				ret = 0;
 				SIMPLEQ_FOREACH_SAFE(notification, &notifymsgs, next, tmp) {
 					memset(msg.data.msg, 0, sizeof(msg.data.msg));
 
@@ -627,12 +625,15 @@  void *network_thread (void *data)
 
 					ret = write_notify_msg(&msg, ctrlconnfd);
 					if (ret < 0) {
-						pthread_mutex_unlock(&msglock);
-						ERROR("Error write notify history on socket ctrl");
-						close(ctrlconnfd);
 						break;
 					}
 				}
+				if (ret < 0) {
+					pthread_mutex_unlock(&msglock);
+					ERROR("Error write notify history on socket ctrl");
+					close(ctrlconnfd);
+					break;
+				}
 
 				/*
 				 * Save the new connection to send notifications to