src/rrdd.c: Remove unused variables and functions.
[rrdd.git] / src / rrdd.c
index 042b331..272b859 100644 (file)
@@ -22,6 +22,8 @@
 #define RRDD_DEBUG 1
 
 #include "rrdd.h"
+#include <glib-2.0/glib.h>
+#include <rrd.h>
 
 #if RRDD_DEBUG
 # define RRDD_LOG(severity, ...) do { fprintf (stderr, __VA_ARGS__); fprintf (stderr, "\n"); } while (0)
@@ -69,7 +71,7 @@ static pthread_mutex_t connetion_threads_lock = PTHREAD_MUTEX_INITIALIZER;
 static int connetion_threads_num = 0;
 
 /* Cache stuff */
-static avl_tree_t     *cache_tree = NULL;
+static GTree          *cache_tree = NULL;
 static cache_item_t   *cache_queue_head = NULL;
 static cache_item_t   *cache_queue_tail = NULL;
 static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -94,30 +96,6 @@ static void sig_term_handler (int signal) /* {{{ */
   do_shutdown++;
 } /* }}} void sig_term_handler */
 
-static int cache_tree_compare (const void *v0, const void *v1) /* {{{ */
-{
-  cache_item_t *c0 = (cache_item_t *) v0;
-  cache_item_t *c1 = (cache_item_t *) v1;
-
-  assert (c0->file != NULL);
-  assert (c1->file != NULL);
-
-  return (strcmp (c0->file, c1->file));
-} /* }}} int cache_tree_compare */
-
-static void cache_tree_free (void *v) /* {{{ */
-{
-  cache_item_t *c = (cache_item_t *) v;
-
-  assert (c->values_num == 0);
-  assert ((c->flags & CI_FLAGS_IN_TREE) != 0);
-  assert ((c->flags & CI_FLAGS_IN_QUEUE) == 0);
-
-  free (c->file);
-  c->file = NULL;
-  free (c);
-} /* }}} void cache_tree_free */
-
 static void *queue_thread_main (void *args) /* {{{ */
 {
   pthread_mutex_lock (&cache_lock);
@@ -198,10 +176,7 @@ static int handle_request_update (int fd, /* {{{ */
 
   time_t now;
 
-  avl_node_t *node;
-  cache_item_t ci_temp;
   cache_item_t *ci;
-
   char answer[4096];
 
   now = time (NULL);
@@ -214,12 +189,10 @@ static int handle_request_update (int fd, /* {{{ */
   file = buffer_ptr;
   buffer_ptr += strlen (file) + 1;
 
-  ci_temp.file = file;
-
   pthread_mutex_lock (&cache_lock);
 
-  node = avl_search (cache_tree, (void *) &ci_temp);
-  if (node == NULL)
+  ci = g_tree_lookup (cache_tree, file);
+  if (ci == NULL)
   {
     ci = (cache_item_t *) malloc (sizeof (cache_item_t));
     if (ci == NULL)
@@ -244,22 +217,11 @@ static int handle_request_update (int fd, /* {{{ */
     ci->last_flush_time = now;
     ci->flags = CI_FLAGS_IN_TREE;
 
-    if (avl_insert (cache_tree, (void *) ci) == NULL)
-    {
-      pthread_mutex_unlock (&cache_lock);
-      RRDD_LOG (LOG_ERR, "handle_request_update: avl_insert failed.");
-      free (ci->file);
-      free (ci);
-      return (-1);
-    }
+    g_tree_insert (cache_tree, (void *) ci->file, (void *) ci);
 
-    RRDD_LOG (LOG_DEBUG, "handle_request_update: Created new AVL node %s.",
+    RRDD_LOG (LOG_DEBUG, "handle_request_update: Created new tree node %s.",
         ci->file);
   }
-  else /* if (ci != NULL) */
-  {
-    ci = (cache_item_t *) node->item;
-  }
   assert (ci != NULL);
 
   while (*buffer_ptr != 0)
@@ -546,7 +508,6 @@ static int open_listen_socket (const char *addr) /* {{{ */
   for (ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
   {
     int fd;
-    struct sockaddr_storage sa;
     listen_socket_t *temp;
 
     temp = (listen_socket_t *) realloc (listen_fds,
@@ -611,7 +572,6 @@ static int close_listen_sockets (void) /* {{{ */
 
 static void *listen_thread_main (void *args) /* {{{ */
 {
-  char buffer[4096];
   struct pollfd *pollfds;
   int pollfds_num;
   int status;
@@ -624,6 +584,9 @@ static void *listen_thread_main (void *args) /* {{{ */
     open_listen_socket (config_listen_address_list[i]);
   }
 
+  if (config_listen_address_list_len < 1)
+    open_listen_socket (RRDD_SOCK_PATH);
+
   if (listen_fds_num < 1)
   {
     RRDD_LOG (LOG_ERR, "listen_thread_main: No listen sockets "
@@ -736,7 +699,9 @@ static void *listen_thread_main (void *args) /* {{{ */
 
 static int daemonize (void) /* {{{ */
 {
+#if !RRDD_DEBUG
   pid_t child;
+#endif
   int status;
 
 #if !RRDD_DEBUG
@@ -785,10 +750,10 @@ static int daemonize (void) /* {{{ */
 
   openlog ("rrdd", LOG_PID, LOG_DAEMON);
 
-  cache_tree = avl_alloc_tree (cache_tree_compare, cache_tree_free);
+  cache_tree = g_tree_new ((GCompareFunc) strcmp);
   if (cache_tree == NULL)
   {
-    RRDD_LOG (LOG_ERR, "daemonize: avl_alloc_tree failed.");
+    RRDD_LOG (LOG_ERR, "daemonize: g_tree_new failed.");
     return (-1);
   }