diff mbox series

notifier: Add error reporting on sendto() failure

Message ID 0195F202-CD4E-4A8C-B6D9-9DFCB8062D71@siemens.com
State Accepted
Headers show
Series notifier: Add error reporting on sendto() failure | expand

Commit Message

Storm, Christian Jan. 29, 2024, 1:08 p.m. UTC
Do not fail silently on sendto() errors, leaving the integrator
wondering about the absence of logs or messages from non-main
SWUpdate processes.

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 core/notifier.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/core/notifier.c b/core/notifier.c
index fe091ced..7fd7eca8 100644
--- a/core/notifier.c
+++ b/core/notifier.c
@@ -236,9 +236,12 @@  void notify(RECOVERY_STATUS status, int error, int level, const char *msg)
 				strlcpy(notifymsg.buf, msg, sizeof(notifymsg.buf) - 1);
 			else
 				notifymsg.buf[0] = '\0';
-			sendto(notifyfd, &notifymsg, sizeof(notifymsg), 0,
-			      (struct sockaddr *) &notify_server,
-				sizeof(struct sockaddr_un));
+			if (-1 == sendto(notifyfd, &notifymsg, sizeof(notifymsg), 0,
+					 (struct sockaddr *)&notify_server,
+					 sizeof(struct sockaddr_un))) {
+				fprintf(stderr, "notify() failed with error %d: %s\n",
+					errno, strerror(errno));
+			}
 		}
 	} else { /* Main process */
 		pthread_mutex_lock(&clients_mutex);