src/rrd_daemon.c: Remove the declaration of strdup.
[rrdtool.git] / src / rrd_daemon.c
index 3af33dc..d446756 100644 (file)
 # define __attribute__(x) /**/
 #endif
 
-#if 0
-/* FIXME: I don't want to declare strdup myself! */
-extern char *strdup (const char *s);
-#endif
-
 /*
  * Types
  */
@@ -167,7 +162,7 @@ static void sig_term_handler (int s __attribute__((unused))) /* {{{ */
  */
 static int enqueue_cache_item (cache_item_t *ci) /* {{{ */
 {
-  RRDD_LOG (LOG_DEBUG, "handle_request_update: Adding %s to the update queue.",
+  RRDD_LOG (LOG_DEBUG, "enqueue_cache_item: Adding %s to the update queue.",
       ci->file);
 
   if (ci == NULL)
@@ -178,6 +173,9 @@ static int enqueue_cache_item (cache_item_t *ci) /* {{{ */
 
   assert (ci->next == NULL);
 
+  if (ci->values_num == 0)
+    return (0);
+
   if (cache_queue_tail == NULL)
     cache_queue_head = ci;
   else
@@ -252,21 +250,12 @@ static void *queue_thread_main (void *args __attribute__((unused))) /* {{{ */
      * something comes in or it's time to do the cache flush. */
     if (cache_queue_head == NULL)
     {
-      struct timespec timeout;
-
-      timeout.tv_sec = next_flush.tv_sec - now.tv_sec;
-      if (next_flush.tv_nsec < (1000 * now.tv_usec))
-      {
-        timeout.tv_sec--;
-        timeout.tv_nsec = 1000000000 + next_flush.tv_nsec
-          - (1000 * now.tv_usec);
-      }
-      else
+      status = pthread_cond_timedwait (&cache_cond, &cache_lock, &next_flush);
+      if ((status != 0) && (status != ETIMEDOUT))
       {
-        timeout.tv_nsec = next_flush.tv_nsec - (1000 * now.tv_usec);
+        RRDD_LOG (LOG_ERR, "queue_thread_main: "
+            "pthread_cond_timedwait returned %i.", status);
       }
-
-      pthread_cond_timedwait (&cache_cond, &cache_lock, &timeout);
     }
 
     /* Check if a value has arrived. This may be NULL if we timed out or there
@@ -325,7 +314,7 @@ static void *queue_thread_main (void *args __attribute__((unused))) /* {{{ */
 } /* }}} void *queue_thread_main */
 
 static int handle_request_update (int fd, /* {{{ */
-    char *buffer, int buffer_size)
+    char *buffer, int buffer_size __attribute__((unused)))
 {
   char *file;
   char *value;
@@ -340,9 +329,6 @@ static int handle_request_update (int fd, /* {{{ */
 
   now = time (NULL);
 
-  RRDD_LOG (LOG_DEBUG, "handle_request_update (%i, %p, %i)",
-      fd, (void *) buffer, buffer_size);
-
   buffer_ptr = buffer;
 
   file = buffer_ptr;
@@ -438,8 +424,6 @@ static int handle_request (int fd) /* {{{ */
   char buffer[4096];
   int buffer_size;
 
-  RRDD_LOG (LOG_DEBUG, "handle_request (%i)", fd);
-
   buffer_size = read (fd, buffer, sizeof (buffer));
   if (buffer_size < 1)
   {
@@ -478,8 +462,6 @@ static void *connection_thread_main (void *args /* {{{ */
   
   fd = *((int *) args);
 
-  RRDD_LOG (LOG_DEBUG, "connection_thread_main: Adding myself to "
-      "connetion_threads[]..");
   pthread_mutex_lock (&connetion_threads_lock);
   {
     pthread_t *temp;
@@ -498,7 +480,6 @@ static void *connection_thread_main (void *args /* {{{ */
     }
   }
   pthread_mutex_unlock (&connetion_threads_lock);
-  RRDD_LOG (LOG_DEBUG, "connection_thread_main: done");
 
   while (do_shutdown == 0)
   {
@@ -523,8 +504,6 @@ 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;
     }
@@ -808,9 +787,6 @@ static void *listen_thread_main (void *args __attribute__((unused))) /* {{{ */
         continue;
       }
 
-      RRDD_LOG (LOG_DEBUG, "listen_thread_main: accept(2) returned fd #%i.",
-          *client_sd);
-
       status = pthread_create (&tid, /* attr = */ NULL, connection_thread_main,
           /* args = */ (void *) client_sd);
       if (status != 0)
@@ -820,10 +796,6 @@ static void *listen_thread_main (void *args __attribute__((unused))) /* {{{ */
         free (client_sd);
         continue;
       }
-
-      RRDD_LOG (LOG_DEBUG, "listen_thread_main: pthread_create succeeded: "
-          "tid = %lu",
-          *((unsigned long *) &tid));
     } /* for (pollfds_num) */
   } /* while (do_shutdown == 0) */