AC_PREFIX_DEFAULT("/opt/rrdd")
-AC_PROG_CC
AC_PROG_CPP
+AC_PROG_CC
+AM_PROG_CC_C_O
AC_PROG_INSTALL
-
+PKG_PROG_PKG_CONFIG
AC_LIBLTDL_CONVENIENCE
AC_SUBST(LTDLINCL)
AC_CONFIG_SUBDIRS(libltdl)
AC_HEADER_STDC
-AC_CHECK_HEADERS(avl.h)
+
+$PKG_CONFIG --exists glib-2.0 2>/dev/null
+if test "$?" != "0"
+then
+ AC_MSG_ERROR("Cannot find the glib-2.0 library.")
+fi
+GLIB_CPPFLAGS=`$PKG_CONFIG --cflags glib-2.0`
+GLIB_LDADD=`$PKG_CONFIG --libs glib-2.0`
+AC_SUBST(GLIB_CPPFLAGS)
+AC_SUBST(GLIB_LDADD)
+
+SAVE_CPPFLAGS="$CPPFLAGS"
+SAVE_LDFLAGS="$LDFLAGS"
+CPPFLAGS="$CPPFLAGS $GLIB_CPPFLAGS"
+LDFLAGS="$LDFLAGS $GLIB_LDADD"
+
+AC_CHECK_HEADERS(glib-2.0/glib.h)
+AC_CHECK_LIB(glib-2.0, g_tree_new, [have_libglib_2_0="yes"], [have_libglib_2_0="no"])
+
+CPPFLAGS="$SAVE_CPPFLAGS"
+LDFLAGS="$SAVE_LDFLAGS"
+
+AC_CHECK_HEADERS(rrd.h)
+AC_CHECK_LIB(rrd_th, rrd_update_r, [have_librrd_th="yes"], [have_librrd_th="no"])
AC_OUTPUT(Makefile src/Makefile)
#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)
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;
time_t now;
- avl_node_t *node;
- cache_item_t ci_temp;
cache_item_t *ci;
-
char answer[4096];
now = time (NULL);
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)
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)
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);
}