{
callback_func_t *cf;
- cf = c_head_get_root (read_heap);
+ cf = c_heap_get_root (read_heap);
if (cf == NULL)
break;
*list = llist_create ();
if (*list == NULL)
{
- ERROR ("plugin: create_register_callback: "
+ ERROR ("plugin: register_callback: "
"llist_create failed.");
destroy_callback (cf);
return (-1);
key = strdup (name);
if (key == NULL)
{
- ERROR ("plugin: create_register_callback: strdup failed.");
+ ERROR ("plugin: register_callback: strdup failed.");
destroy_callback (cf);
return (-1);
}
le = llentry_create (key, cf);
if (le == NULL)
{
- ERROR ("plugin: create_register_callback: "
+ ERROR ("plugin: register_callback: "
"llentry_create failed.");
free (key);
destroy_callback (cf);
old_cf = le->value;
le->value = cf;
+ WARNING ("plugin: register_callback: "
+ "a callback named `%s' already exists - "
+ "overwriting the old entry!", name);
+
destroy_callback (old_cf);
sfree (key);
}
return (0);
}
+static _Bool timeout_reached(struct timespec timeout)
+{
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ return (now.tv_sec >= timeout.tv_sec && now.tv_usec >= (timeout.tv_nsec / 1000));
+}
+
static void *plugin_read_thread (void __attribute__((unused)) *args)
{
while (read_loop != 0)
struct timeval now;
int status;
int rf_type;
+ int rc;
/* Get the read function that needs to be read next. */
- rf = c_head_get_root (read_heap);
+ rf = c_heap_get_root (read_heap);
if (rf == NULL)
{
struct timespec abstime;
/* sleep until this entry is due,
* using pthread_cond_timedwait */
pthread_mutex_lock (&read_lock);
- pthread_cond_timedwait (&read_cond, &read_lock,
+ /* In pthread_cond_timedwait, spurious wakeups are possible
+ * (and really happen, at least on NetBSD with > 1 CPU), thus
+ * we need to re-evaluate the condition every time
+ * pthread_cond_timedwait returns. */
+ rc = 0;
+ while (!timeout_reached(rf->rf_next_read) && rc == 0) {
+ rc = pthread_cond_timedwait (&read_cond, &read_lock,
&rf->rf_next_read);
+ }
+
/* Must hold `real_lock' when accessing `rf->rf_type'. */
rf_type = rf->rf_type;
pthread_mutex_unlock (&read_lock);
{
read_func_t *rf;
- rf = c_head_get_root (read_heap);
+ rf = c_heap_get_root (read_heap);
if (rf == NULL)
break;
va_list ap;
llentry_t *le;
- if (list_log == NULL)
- return;
-
#if !COLLECT_DEBUG
if (level >= LOG_DEBUG)
return;
msg[sizeof (msg) - 1] = '\0';
va_end (ap);
+ if (list_log == NULL)
+ {
+ fprintf (stderr, "%s\n", msg);
+ return;
+ }
+
le = llist_head (list_log);
while (le != NULL)
{