src/rrdd.c: Add a debug message for disconnecting sockets.
[rrdd.git] / src / rrdd.c
index 8aa5a58..4ae3daa 100644 (file)
@@ -188,6 +188,7 @@ static int handle_request_update (int fd, /* {{{ */
   char *value;
   char *buffer_ptr;
   int values_num = 0;
+  int status;
 
   time_t now;
 
@@ -305,7 +306,13 @@ static int handle_request_update (int fd, /* {{{ */
   snprintf (answer, sizeof (answer), "0 Enqueued %i value(s)\n", values_num);
   answer[sizeof (answer) - 1] = 0;
 
-  write (fd, answer, sizeof (answer));
+  status = write (fd, answer, sizeof (answer));
+  if (status < 0)
+  {
+    status = errno;
+    RRDD_LOG (LOG_INFO, "handle_request_update: write(2) returned an error.");
+    return (status);
+  }
 
   return (0);
 } /* }}} int handle_request_update */
@@ -399,13 +406,16 @@ static void *connection_thread_main (void *args) /* {{{ */
 
     if ((pollfd.revents & POLLHUP) != 0) /* normal shutdown */
     {
+      RRDD_LOG (LOG_DEBUG, "connection_thread_main: "
+          "poll(2) returned POLLHUP.");
       close (fd);
       break;
     }
     else if ((pollfd.revents & (POLLIN | POLLPRI)) == 0)
     {
-      RRDD_LOG (LOG_WARNING, "connection_thread_main: poll(2) returned "
-          "something unexpected.");
+      RRDD_LOG (LOG_WARNING, "connection_thread_main: "
+          "poll(2) returned something unexpected: %#04hx",
+          pollfd.revents);
       close (fd);
       break;
     }
@@ -632,6 +642,10 @@ static int daemonize (void) /* {{{ */
     memset (&sa, 0, sizeof (sa));
     sa.sa_handler = sig_term_handler;
     sigaction (SIGINT, &sa, NULL);
+
+    memset (&sa, 0, sizeof (sa));
+    sa.sa_handler = SIG_IGN;
+    sigaction (SIGPIPE, &sa, NULL);
   }
 
   openlog ("rrdd", LOG_PID, LOG_DAEMON);