static int config_listen_address_list_len = 0;
static uint64_t stats_queue_length = 0;
-static uint64_t stats_updates_total = 0;
-static uint64_t stats_values_total = 0;
+static uint64_t stats_updates_written = 0;
+static uint64_t stats_data_sets_written = 0;
static pthread_mutex_t stats_lock = PTHREAD_MUTEX_INITIALIZER;
/*
{
int did_insert = 0;
- RRDD_LOG (LOG_DEBUG, "enqueue_cache_item: Adding %s to the update queue.",
- ci->file);
-
if (ci == NULL)
return (-1);
pthread_mutex_unlock (&cache_lock);
- RRDD_LOG (LOG_DEBUG, "queue_thread_main: rrd_update (%s, %i, %p)",
- file, values_num, (void *) values);
-
status = rrd_update_r (file, NULL, values_num, (void *) values);
if (status != 0)
{
for (i = 0; i < values_num; i++)
free (values[i]);
- pthread_mutex_lock (&stats_lock);
- stats_updates_total++;
- stats_values_total += values_num;
- pthread_mutex_unlock (&stats_lock);
+ if (status == 0)
+ {
+ pthread_mutex_lock (&stats_lock);
+ stats_updates_written++;
+ stats_data_sets_written += values_num;
+ pthread_mutex_unlock (&stats_lock);
+ }
pthread_mutex_lock (&cache_lock);
pthread_cond_broadcast (&flush_cond);
} /* while (do_shutdown == 0) */
pthread_mutex_unlock (&cache_lock);
- RRDD_LOG (LOG_DEBUG, "queue_thread_main: Exiting.");
-
return (NULL);
} /* }}} void *queue_thread_main */
char outbuf[4096];
uint64_t copy_queue_length;
- uint64_t copy_updates_total;
- uint64_t copy_values_total;
+ uint64_t copy_updates_written;
+ uint64_t copy_data_sets_written;
- uint64_t tree_nodes;
+ uint64_t tree_nodes_number;
uint64_t tree_depth;
pthread_mutex_lock (&stats_lock);
- copy_queue_length = stats_queue_length;
- copy_updates_total = stats_updates_total;
- copy_values_total = stats_values_total;
+ copy_queue_length = stats_queue_length;
+ copy_updates_written = stats_updates_written;
+ copy_data_sets_written = stats_data_sets_written;
pthread_mutex_unlock (&stats_lock);
pthread_mutex_lock (&cache_lock);
- tree_nodes = (uint64_t) g_tree_nnodes (cache_tree);
- tree_depth = (uint64_t) g_tree_height (cache_tree);
+ tree_nodes_number = (uint64_t) g_tree_nnodes (cache_tree);
+ tree_depth = (uint64_t) g_tree_height (cache_tree);
pthread_mutex_unlock (&cache_lock);
#define RRDD_STATS_SEND \
RRDD_STATS_SEND;
snprintf (outbuf, sizeof (outbuf),
- "UpdatesWritten: %"PRIu64"\n", copy_updates_total);
+ "UpdatesWritten: %"PRIu64"\n", copy_updates_written);
RRDD_STATS_SEND;
snprintf (outbuf, sizeof (outbuf),
- "ValuesWritten: %"PRIu64"\n", copy_values_total);
+ "DataSetsWritten: %"PRIu64"\n", copy_data_sets_written);
RRDD_STATS_SEND;
snprintf (outbuf, sizeof (outbuf),
- "TreeNodesNumber: %"PRIu64"\n", tree_nodes);
+ "TreeNodesNumber: %"PRIu64"\n", tree_nodes_number);
RRDD_STATS_SEND;
snprintf (outbuf, sizeof (outbuf),
ci = g_tree_lookup (cache_tree, file);
if (ci == NULL) /* {{{ */
{
+ struct stat statbuf;
+
+ memset (&statbuf, 0, sizeof (statbuf));
+ status = stat (file, &statbuf);
+ if (status != 0)
+ {
+ pthread_mutex_unlock (&cache_lock);
+ RRDD_LOG (LOG_ERR, "handle_request_update: stat (%s) failed.", file);
+
+ status = errno;
+ if (status == ENOENT)
+ snprintf (answer, sizeof (answer), "-1 No such file: %s", file);
+ else
+ snprintf (answer, sizeof (answer), "-1 stat failed with error %i.\n",
+ status);
+ RRDD_UPDATE_SEND;
+ return (0);
+ }
+ if (!S_ISREG (statbuf.st_mode))
+ {
+ pthread_mutex_unlock (&cache_lock);
+
+ snprintf (answer, sizeof (answer), "-1 Not a regular file: %s", file);
+ RRDD_UPDATE_SEND;
+ return (0);
+ }
+
ci = (cache_item_t *) malloc (sizeof (cache_item_t));
if (ci == NULL)
{
ci->flags = CI_FLAGS_IN_TREE;
g_tree_insert (cache_tree, (void *) ci->file, (void *) ci);
-
- RRDD_LOG (LOG_DEBUG, "handle_request_update: Created new tree node %s.",
- ci->file);
} /* }}} */
assert (ci != NULL);
int i;
for (i = 0; i < config_listen_address_list_len; i++)
- {
- RRDD_LOG (LOG_DEBUG, "listen_thread_main: config_listen_address_list[%i] "
- "= %s", i, config_listen_address_list[i]);
open_listen_socket (config_listen_address_list[i]);
- }
if (config_listen_address_list_len < 1)
open_listen_socket (RRDCACHED_DEFAULT_ADDRESS);
struct sockaddr_storage client_sa;
socklen_t client_sa_size;
pthread_t tid;
+ pthread_attr_t attr;
if (pollfds[i].revents == 0)
continue;
continue;
}
- status = pthread_create (&tid, /* attr = */ NULL, connection_thread_main,
+ pthread_attr_init (&attr);
+ pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+
+ status = pthread_create (&tid, &attr, connection_thread_main,
/* args = */ (void *) client_sd);
if (status != 0)
{
}
pthread_mutex_unlock (&connetion_threads_lock);
- RRDD_LOG (LOG_DEBUG, "listen_thread_main: Exiting.");
-
return (NULL);
} /* }}} void *listen_thread_main */
memset (&sa_term, 0, sizeof (sa_term));
sa_term.sa_handler = sig_term_handler;
- sigaction (SIGINT, &sa_term, NULL);
+ sigaction (SIGTERM, &sa_term, NULL);
memset (&sa_pipe, 0, sizeof (sa_pipe));
sa_pipe.sa_handler = SIG_IGN;
static int cleanup (void) /* {{{ */
{
- RRDD_LOG (LOG_DEBUG, "cleanup ()");
-
do_shutdown++;
- RRDD_LOG (LOG_DEBUG, "cleanup: Joining queue_thread..");
pthread_cond_signal (&cache_cond);
pthread_join (queue_thread, /* return = */ NULL);
- RRDD_LOG (LOG_DEBUG, "cleanup: done");
remove_pidfile ();