about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNakidai <nakidai@disroot.org>2025-08-30 15:39:29 +0300
committerNakidai <nakidai@disroot.org>2025-08-30 15:39:29 +0300
commit41635adb62cb94bd46517a9da3179c1a7c06d477 (patch)
treee43a2a62bee3d54b500f9f96c11f3d809390601b
parent33fdfea31bbb0da3e6becdc2f78022f05c0a17d8 (diff)
downloadsami-41635adb62cb94bd46517a9da3179c1a7c06d477.tar.gz
sami-41635adb62cb94bd46517a9da3179c1a7c06d477.zip
Implement logging
-rw-r--r--sami.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/sami.c b/sami.c
index 69f0796..8ae01c6 100644
--- a/sami.c
+++ b/sami.c
@@ -2,6 +2,7 @@
 
 #include <errno.h>
 #include <signal.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -20,6 +21,9 @@ static SAMI actors[ACTORS_MAX];
 char buffer[MESSAGE_LENGTH_MAX];
 static int self_fd;
 
+#define log(level, message) \
+	fprintf("%s:%d [%s]: %s\n", __FILE__, __LINE__, level, message)
+
 static ssize_t findspace(void)
 {
 	size_t i;
@@ -59,10 +63,10 @@ retry:
 		waitpid(-1, 0, WNOHANG);
 		res = poll(pfd, ACTORS_MAX, 0);
 		if (res == -1)
-			if (errno = EINTR)
+			if (errno == EINTR)
 				goto retry;
-			else /* TODO: log fail */
-				exit(1);
+			else
+				log("CRITICAL", strerror(errno)), exit(1);
 		else if (res == 0)
 			goto retry;
 
@@ -72,7 +76,11 @@ retry:
 				break;
 
 			sz = recv(pfd[i].fd, buffer, sizeof(buffer), 0);
-			/* TODO: log if sz == -1 */
+			if (sz == -1)
+			{
+				log("WARNING", strerror(errno));
+				continue;
+			}
 			if (handler(&actor[i], buffer, sz))
 				goto end;
 		}