2 * collectd - src/plugin.c
3 * Copyright (C) 2005-2011 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at collectd.org>
20 * Sebastian Harl <sh at tokkee.org>
24 #include "utils_complain.h"
34 #include "configfile.h"
35 #include "utils_avltree.h"
36 #include "utils_llist.h"
37 #include "utils_heap.h"
38 #include "utils_cache.h"
39 #include "filter_chain.h"
44 struct callback_func_s
50 typedef struct callback_func_s callback_func_t;
54 #define RF_REMOVE 65535
57 /* `read_func_t' "inherits" from `callback_func_t'.
58 * The `rf_super' member MUST be the first one in this structure! */
59 #define rf_callback rf_super.cf_callback
60 #define rf_udata rf_super.cf_udata
61 #define rf_ctx rf_super.cf_ctx
62 callback_func_t rf_super;
63 char rf_group[DATA_MAX_NAME_LEN];
64 char rf_name[DATA_MAX_NAME_LEN];
66 struct timespec rf_interval;
67 struct timespec rf_effective_interval;
68 struct timespec rf_next_read;
70 typedef struct read_func_s read_func_t;
75 static llist_t *list_init;
76 static llist_t *list_write;
77 static llist_t *list_flush;
78 static llist_t *list_missing;
79 static llist_t *list_shutdown;
80 static llist_t *list_log;
81 static llist_t *list_notification;
83 static fc_chain_t *pre_cache_chain = NULL;
84 static fc_chain_t *post_cache_chain = NULL;
86 static c_avl_tree_t *data_sets;
88 static char *plugindir = NULL;
90 static c_heap_t *read_heap = NULL;
91 static llist_t *read_list;
92 static int read_loop = 1;
93 static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
94 static pthread_cond_t read_cond = PTHREAD_COND_INITIALIZER;
95 static pthread_t *read_threads = NULL;
96 static int read_threads_num = 0;
98 static pthread_key_t plugin_ctx_key;
99 static _Bool plugin_ctx_key_initialized = 0;
104 static const char *plugin_get_dir (void)
106 if (plugindir == NULL)
112 static void destroy_callback (callback_func_t *cf) /* {{{ */
117 if ((cf->cf_udata.data != NULL) && (cf->cf_udata.free_func != NULL))
119 cf->cf_udata.free_func (cf->cf_udata.data);
120 cf->cf_udata.data = NULL;
121 cf->cf_udata.free_func = NULL;
124 } /* }}} void destroy_callback */
126 static void destroy_all_callbacks (llist_t **list) /* {{{ */
133 le = llist_head (*list);
141 destroy_callback (le->value);
147 llist_destroy (*list);
149 } /* }}} void destroy_all_callbacks */
151 static void destroy_read_heap (void) /* {{{ */
153 if (read_heap == NULL)
160 cf = c_heap_get_root (read_heap);
164 destroy_callback (cf);
167 c_heap_destroy (read_heap);
169 } /* }}} void destroy_read_heap */
171 static int register_callback (llist_t **list, /* {{{ */
172 const char *name, callback_func_t *cf)
179 *list = llist_create ();
182 ERROR ("plugin: register_callback: "
183 "llist_create failed.");
184 destroy_callback (cf);
192 ERROR ("plugin: register_callback: strdup failed.");
193 destroy_callback (cf);
197 le = llist_search (*list, name);
200 le = llentry_create (key, cf);
203 ERROR ("plugin: register_callback: "
204 "llentry_create failed.");
206 destroy_callback (cf);
210 llist_append (*list, le);
214 callback_func_t *old_cf;
219 WARNING ("plugin: register_callback: "
220 "a callback named `%s' already exists - "
221 "overwriting the old entry!", name);
223 destroy_callback (old_cf);
228 } /* }}} int register_callback */
230 static int create_register_callback (llist_t **list, /* {{{ */
231 const char *name, void *callback, user_data_t *ud)
235 cf = (callback_func_t *) malloc (sizeof (*cf));
238 ERROR ("plugin: create_register_callback: malloc failed.");
241 memset (cf, 0, sizeof (*cf));
243 cf->cf_callback = callback;
246 cf->cf_udata.data = NULL;
247 cf->cf_udata.free_func = NULL;
254 cf->cf_ctx = plugin_get_ctx ();
256 return (register_callback (list, name, cf));
257 } /* }}} int create_register_callback */
259 static int plugin_unregister (llist_t *list, const char *name) /* {{{ */
266 e = llist_search (list, name);
270 llist_remove (list, e);
273 destroy_callback (e->value);
278 } /* }}} int plugin_unregister */
281 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
282 * object, but it will bitch about a shared object not having a
283 * ``module_register'' symbol..
285 static int plugin_load_file (char *file, uint32_t flags)
288 void (*reg_handle) (void);
291 lt_dlerror (); /* clear errors */
293 #if LIBTOOL_VERSION == 2
294 if (flags & PLUGIN_FLAGS_GLOBAL) {
296 lt_dladvise_init(&advise);
297 lt_dladvise_global(&advise);
298 dlh = lt_dlopenadvise(file, advise);
299 lt_dladvise_destroy(&advise);
301 dlh = lt_dlopen (file);
303 #else /* if LIBTOOL_VERSION == 1 */
304 if (flags & PLUGIN_FLAGS_GLOBAL)
305 WARNING ("plugin_load_file: The global flag is not supported, "
306 "libtool 2 is required for this.");
307 dlh = lt_dlopen (file);
312 char errbuf[1024] = "";
314 ssnprintf (errbuf, sizeof (errbuf),
315 "lt_dlopen (\"%s\") failed: %s. "
316 "The most common cause for this problem are "
317 "missing dependencies. Use ldd(1) to check "
318 "the dependencies of the plugin "
320 file, lt_dlerror ());
322 ERROR ("%s", errbuf);
323 /* Make sure this is printed to STDERR in any case, but also
324 * make sure it's printed only once. */
325 if (list_log != NULL)
326 fprintf (stderr, "ERROR: %s\n", errbuf);
331 if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
333 WARNING ("Couldn't find symbol \"module_register\" in \"%s\": %s\n",
334 file, lt_dlerror ());
344 static _Bool timeout_reached(struct timespec timeout)
347 gettimeofday(&now, NULL);
348 return (now.tv_sec >= timeout.tv_sec && now.tv_usec >= (timeout.tv_nsec / 1000));
351 static void *plugin_read_thread (void __attribute__((unused)) *args)
353 while (read_loop != 0)
356 plugin_ctx_t old_ctx;
362 /* Get the read function that needs to be read next.
363 * We don't need to hold "read_lock" for the heap, but we need
364 * to call c_heap_get_root() and pthread_cond_wait() in the
365 * same protected block. */
366 pthread_mutex_lock (&read_lock);
367 rf = c_heap_get_root (read_heap);
370 pthread_cond_wait (&read_cond, &read_lock);
371 pthread_mutex_unlock (&read_lock);
374 pthread_mutex_unlock (&read_lock);
376 if ((rf->rf_interval.tv_sec == 0) && (rf->rf_interval.tv_nsec == 0))
378 /* this should not happen, because the interval is set
379 * for each plugin when loading it
380 * XXX: issue a warning? */
383 CDTIME_T_TO_TIMESPEC (plugin_get_interval (), &rf->rf_interval);
385 rf->rf_effective_interval = rf->rf_interval;
387 CDTIME_T_TO_TIMESPEC (now, &rf->rf_next_read);
390 /* sleep until this entry is due,
391 * using pthread_cond_timedwait */
392 pthread_mutex_lock (&read_lock);
393 /* In pthread_cond_timedwait, spurious wakeups are possible
394 * (and really happen, at least on NetBSD with > 1 CPU), thus
395 * we need to re-evaluate the condition every time
396 * pthread_cond_timedwait returns. */
398 while ((read_loop != 0)
399 && !timeout_reached(rf->rf_next_read)
402 rc = pthread_cond_timedwait (&read_cond, &read_lock,
406 /* Must hold `read_lock' when accessing `rf->rf_type'. */
407 rf_type = rf->rf_type;
408 pthread_mutex_unlock (&read_lock);
410 /* Check if we're supposed to stop.. This may have interrupted
414 /* Insert `rf' again, so it can be free'd correctly */
415 c_heap_insert (read_heap, rf);
419 /* The entry has been marked for deletion. The linked list
420 * entry has already been removed by `plugin_unregister_read'.
421 * All we have to do here is free the `read_func_t' and
423 if (rf_type == RF_REMOVE)
425 DEBUG ("plugin_read_thread: Destroying the `%s' "
426 "callback.", rf->rf_name);
427 destroy_callback ((callback_func_t *) rf);
432 DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
434 old_ctx = plugin_set_ctx (rf->rf_ctx);
436 if (rf_type == RF_SIMPLE)
438 int (*callback) (void);
440 callback = rf->rf_callback;
441 status = (*callback) ();
445 plugin_read_cb callback;
447 assert (rf_type == RF_COMPLEX);
449 callback = rf->rf_callback;
450 status = (*callback) (&rf->rf_udata);
453 plugin_set_ctx (old_ctx);
455 /* If the function signals failure, we will increase the
456 * intervals in which it will be called. */
459 rf->rf_effective_interval.tv_sec *= 2;
460 rf->rf_effective_interval.tv_nsec *= 2;
461 NORMALIZE_TIMESPEC (rf->rf_effective_interval);
463 if (rf->rf_effective_interval.tv_sec >= 86400)
465 rf->rf_effective_interval.tv_sec = 86400;
466 rf->rf_effective_interval.tv_nsec = 0;
469 NOTICE ("read-function of plugin `%s' failed. "
470 "Will suspend it for %i seconds.",
472 (int) rf->rf_effective_interval.tv_sec);
476 /* Success: Restore the interval, if it was changed. */
477 rf->rf_effective_interval = rf->rf_interval;
480 /* update the ``next read due'' field */
483 DEBUG ("plugin_read_thread: Effective interval of the "
484 "%s plugin is %i.%09i.",
486 (int) rf->rf_effective_interval.tv_sec,
487 (int) rf->rf_effective_interval.tv_nsec);
489 /* Calculate the next (absolute) time at which this function
490 * should be called. */
491 rf->rf_next_read.tv_sec = rf->rf_next_read.tv_sec
492 + rf->rf_effective_interval.tv_sec;
493 rf->rf_next_read.tv_nsec = rf->rf_next_read.tv_nsec
494 + rf->rf_effective_interval.tv_nsec;
495 NORMALIZE_TIMESPEC (rf->rf_next_read);
497 /* Check, if `rf_next_read' is in the past. */
498 if (TIMESPEC_TO_CDTIME_T (&rf->rf_next_read) < now)
500 /* `rf_next_read' is in the past. Insert `now'
501 * so this value doesn't trail off into the
503 CDTIME_T_TO_TIMESPEC (now, &rf->rf_next_read);
506 DEBUG ("plugin_read_thread: Next read of the %s plugin at %i.%09i.",
508 (int) rf->rf_next_read.tv_sec,
509 (int) rf->rf_next_read.tv_nsec);
511 /* Re-insert this read function into the heap again. */
512 c_heap_insert (read_heap, rf);
513 } /* while (read_loop) */
517 } /* void *plugin_read_thread */
519 static void start_read_threads (int num)
523 if (read_threads != NULL)
526 read_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
527 if (read_threads == NULL)
529 ERROR ("plugin: start_read_threads: calloc failed.");
533 read_threads_num = 0;
534 for (i = 0; i < num; i++)
536 if (pthread_create (read_threads + read_threads_num, NULL,
537 plugin_read_thread, NULL) == 0)
543 ERROR ("plugin: start_read_threads: pthread_create failed.");
547 } /* void start_read_threads */
549 static void stop_read_threads (void)
553 if (read_threads == NULL)
556 INFO ("collectd: Stopping %i read threads.", read_threads_num);
558 pthread_mutex_lock (&read_lock);
560 DEBUG ("plugin: stop_read_threads: Signalling `read_cond'");
561 pthread_cond_broadcast (&read_cond);
562 pthread_mutex_unlock (&read_lock);
564 for (i = 0; i < read_threads_num; i++)
566 if (pthread_join (read_threads[i], NULL) != 0)
568 ERROR ("plugin: stop_read_threads: pthread_join failed.");
570 read_threads[i] = (pthread_t) 0;
572 sfree (read_threads);
573 read_threads_num = 0;
574 } /* void stop_read_threads */
579 void plugin_set_dir (const char *dir)
581 if (plugindir != NULL)
586 else if ((plugindir = strdup (dir)) == NULL)
589 ERROR ("strdup failed: %s",
590 sstrerror (errno, errbuf, sizeof (errbuf)));
595 int plugin_load (const char *type, uint32_t flags)
599 char filename[BUFSIZE] = "";
600 char typename[BUFSIZE];
607 DEBUG ("type = %s", type);
609 dir = plugin_get_dir ();
612 /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
613 * type when matching the filename */
614 status = ssnprintf (typename, sizeof (typename), "%s.so", type);
615 if ((status < 0) || ((size_t) status >= sizeof (typename)))
617 WARNING ("snprintf: truncated: `%s.so'", type);
620 typename_len = strlen (typename);
622 if ((dh = opendir (dir)) == NULL)
625 ERROR ("opendir (%s): %s", dir,
626 sstrerror (errno, errbuf, sizeof (errbuf)));
630 while ((de = readdir (dh)) != NULL)
632 if (strncasecmp (de->d_name, typename, typename_len))
635 status = ssnprintf (filename, sizeof (filename),
636 "%s/%s", dir, de->d_name);
637 if ((status < 0) || ((size_t) status >= sizeof (filename)))
639 WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name);
643 if (lstat (filename, &statbuf) == -1)
646 WARNING ("stat %s: %s", filename,
647 sstrerror (errno, errbuf, sizeof (errbuf)));
650 else if (!S_ISREG (statbuf.st_mode))
652 /* don't follow symlinks */
653 WARNING ("stat %s: not a regular file", filename);
657 if (plugin_load_file (filename, flags) == 0)
665 fprintf (stderr, "Unable to load plugin %s.\n", type);
671 if (filename[0] == '\0')
672 fprintf (stderr, "Could not find plugin %s.\n", type);
678 * The `register_*' functions follow
680 int plugin_register_config (const char *name,
681 int (*callback) (const char *key, const char *val),
682 const char **keys, int keys_num)
684 cf_register (name, callback, keys, keys_num);
686 } /* int plugin_register_config */
688 int plugin_register_complex_config (const char *type,
689 int (*callback) (oconfig_item_t *))
691 return (cf_register_complex (type, callback));
692 } /* int plugin_register_complex_config */
694 int plugin_register_init (const char *name,
695 int (*callback) (void))
697 return (create_register_callback (&list_init, name, (void *) callback,
698 /* user_data = */ NULL));
699 } /* plugin_register_init */
701 static int plugin_compare_read_func (const void *arg0, const void *arg1)
703 const read_func_t *rf0;
704 const read_func_t *rf1;
709 if (rf0->rf_next_read.tv_sec < rf1->rf_next_read.tv_sec)
711 else if (rf0->rf_next_read.tv_sec > rf1->rf_next_read.tv_sec)
713 else if (rf0->rf_next_read.tv_nsec < rf1->rf_next_read.tv_nsec)
715 else if (rf0->rf_next_read.tv_nsec > rf1->rf_next_read.tv_nsec)
719 } /* int plugin_compare_read_func */
721 /* Add a read function to both, the heap and a linked list. The linked list if
722 * used to look-up read functions, especially for the remove function. The heap
723 * is used to determine which plugin to read next. */
724 static int plugin_insert_read (read_func_t *rf)
729 pthread_mutex_lock (&read_lock);
731 if (read_list == NULL)
733 read_list = llist_create ();
734 if (read_list == NULL)
736 pthread_mutex_unlock (&read_lock);
737 ERROR ("plugin_insert_read: read_list failed.");
742 if (read_heap == NULL)
744 read_heap = c_heap_create (plugin_compare_read_func);
745 if (read_heap == NULL)
747 pthread_mutex_unlock (&read_lock);
748 ERROR ("plugin_insert_read: c_heap_create failed.");
753 le = llist_search (read_list, rf->rf_name);
756 pthread_mutex_unlock (&read_lock);
757 WARNING ("The read function \"%s\" is already registered. "
758 "Check for duplicate \"LoadPlugin\" lines "
759 "in your configuration!",
764 le = llentry_create (rf->rf_name, rf);
767 pthread_mutex_unlock (&read_lock);
768 ERROR ("plugin_insert_read: llentry_create failed.");
772 status = c_heap_insert (read_heap, rf);
775 pthread_mutex_unlock (&read_lock);
776 ERROR ("plugin_insert_read: c_heap_insert failed.");
777 llentry_destroy (le);
781 /* This does not fail. */
782 llist_append (read_list, le);
784 /* Wake up all the read threads. */
785 pthread_cond_broadcast (&read_cond);
786 pthread_mutex_unlock (&read_lock);
788 } /* int plugin_insert_read */
790 static int read_cb_wrapper (user_data_t *ud)
792 int (*callback) (void);
799 } /* int read_cb_wrapper */
801 int plugin_register_read (const char *name,
802 int (*callback) (void))
805 plugin_ctx_t ctx = plugin_get_ctx ();
808 if (ctx.interval != 0) {
809 /* If ctx.interval is not zero (== use the plugin or global
810 * interval), we need to use the "complex" read callback,
811 * because only that allows to specify a different interval.
812 * Wrap the callback using read_cb_wrapper(). */
813 struct timespec interval;
814 user_data_t user_data;
816 user_data.data = callback;
817 user_data.free_func = NULL;
819 CDTIME_T_TO_TIMESPEC (ctx.interval, &interval);
820 return plugin_register_complex_read (/* group = */ NULL,
821 name, read_cb_wrapper, &interval, &user_data);
824 DEBUG ("plugin_register_read: default_interval = %.3f",
825 CDTIME_T_TO_DOUBLE(plugin_get_interval ()));
827 rf = malloc (sizeof (*rf));
830 ERROR ("plugin_register_read: malloc failed.");
834 memset (rf, 0, sizeof (read_func_t));
835 rf->rf_callback = (void *) callback;
836 rf->rf_udata.data = NULL;
837 rf->rf_udata.free_func = NULL;
839 rf->rf_group[0] = '\0';
840 sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
841 rf->rf_type = RF_SIMPLE;
842 rf->rf_interval.tv_sec = 0;
843 rf->rf_interval.tv_nsec = 0;
844 rf->rf_effective_interval = rf->rf_interval;
846 status = plugin_insert_read (rf);
851 } /* int plugin_register_read */
853 int plugin_register_complex_read (const char *group, const char *name,
854 plugin_read_cb callback,
855 const struct timespec *interval,
856 user_data_t *user_data)
859 plugin_ctx_t ctx = plugin_get_ctx ();
862 rf = malloc (sizeof (*rf));
865 ERROR ("plugin_register_complex_read: malloc failed.");
869 memset (rf, 0, sizeof (read_func_t));
870 rf->rf_callback = (void *) callback;
872 sstrncpy (rf->rf_group, group, sizeof (rf->rf_group));
874 rf->rf_group[0] = '\0';
875 sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
876 rf->rf_type = RF_COMPLEX;
877 if (interval != NULL)
879 rf->rf_interval = *interval;
881 else if (ctx.interval != 0)
883 CDTIME_T_TO_TIMESPEC (ctx.interval, &rf->rf_interval);
885 rf->rf_effective_interval = rf->rf_interval;
887 DEBUG ("plugin_register_read: interval = %i.%09i",
888 (int) rf->rf_interval.tv_sec,
889 (int) rf->rf_interval.tv_nsec);
892 if (user_data == NULL)
894 rf->rf_udata.data = NULL;
895 rf->rf_udata.free_func = NULL;
899 rf->rf_udata = *user_data;
904 status = plugin_insert_read (rf);
909 } /* int plugin_register_complex_read */
911 int plugin_register_write (const char *name,
912 plugin_write_cb callback, user_data_t *ud)
914 return (create_register_callback (&list_write, name,
915 (void *) callback, ud));
916 } /* int plugin_register_write */
918 int plugin_register_flush (const char *name,
919 plugin_flush_cb callback, user_data_t *ud)
921 return (create_register_callback (&list_flush, name,
922 (void *) callback, ud));
923 } /* int plugin_register_flush */
925 int plugin_register_missing (const char *name,
926 plugin_missing_cb callback, user_data_t *ud)
928 return (create_register_callback (&list_missing, name,
929 (void *) callback, ud));
930 } /* int plugin_register_missing */
932 int plugin_register_shutdown (const char *name,
933 int (*callback) (void))
935 return (create_register_callback (&list_shutdown, name,
936 (void *) callback, /* user_data = */ NULL));
937 } /* int plugin_register_shutdown */
939 int plugin_register_data_set (const data_set_t *ds)
944 if ((data_sets != NULL)
945 && (c_avl_get (data_sets, ds->type, NULL) == 0))
947 NOTICE ("Replacing DS `%s' with another version.", ds->type);
948 plugin_unregister_data_set (ds->type);
950 else if (data_sets == NULL)
952 data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
953 if (data_sets == NULL)
957 ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
960 memcpy(ds_copy, ds, sizeof (data_set_t));
962 ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
964 if (ds_copy->ds == NULL)
970 for (i = 0; i < ds->ds_num; i++)
971 memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
973 return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
974 } /* int plugin_register_data_set */
976 int plugin_register_log (const char *name,
977 plugin_log_cb callback, user_data_t *ud)
979 return (create_register_callback (&list_log, name,
980 (void *) callback, ud));
981 } /* int plugin_register_log */
983 int plugin_register_notification (const char *name,
984 plugin_notification_cb callback, user_data_t *ud)
986 return (create_register_callback (&list_notification, name,
987 (void *) callback, ud));
988 } /* int plugin_register_log */
990 int plugin_unregister_config (const char *name)
992 cf_unregister (name);
994 } /* int plugin_unregister_config */
996 int plugin_unregister_complex_config (const char *name)
998 cf_unregister_complex (name);
1000 } /* int plugin_unregister_complex_config */
1002 int plugin_unregister_init (const char *name)
1004 return (plugin_unregister (list_init, name));
1007 int plugin_unregister_read (const char *name) /* {{{ */
1015 pthread_mutex_lock (&read_lock);
1017 if (read_list == NULL)
1019 pthread_mutex_unlock (&read_lock);
1023 le = llist_search (read_list, name);
1026 pthread_mutex_unlock (&read_lock);
1027 WARNING ("plugin_unregister_read: No such read function: %s",
1032 llist_remove (read_list, le);
1035 assert (rf != NULL);
1036 rf->rf_type = RF_REMOVE;
1038 pthread_mutex_unlock (&read_lock);
1040 llentry_destroy (le);
1042 DEBUG ("plugin_unregister_read: Marked `%s' for removal.", name);
1045 } /* }}} int plugin_unregister_read */
1047 static int compare_read_func_group (llentry_t *e, void *ud) /* {{{ */
1049 read_func_t *rf = e->value;
1052 return strcmp (rf->rf_group, (const char *)group);
1053 } /* }}} int compare_read_func_group */
1055 int plugin_unregister_read_group (const char *group) /* {{{ */
1065 pthread_mutex_lock (&read_lock);
1067 if (read_list == NULL)
1069 pthread_mutex_unlock (&read_lock);
1075 le = llist_search_custom (read_list,
1076 compare_read_func_group, (void *)group);
1083 llist_remove (read_list, le);
1086 assert (rf != NULL);
1087 rf->rf_type = RF_REMOVE;
1089 llentry_destroy (le);
1091 DEBUG ("plugin_unregister_read_group: "
1092 "Marked `%s' (group `%s') for removal.",
1093 rf->rf_name, group);
1096 pthread_mutex_unlock (&read_lock);
1100 WARNING ("plugin_unregister_read_group: No such "
1101 "group of read function: %s", group);
1106 } /* }}} int plugin_unregister_read_group */
1108 int plugin_unregister_write (const char *name)
1110 return (plugin_unregister (list_write, name));
1113 int plugin_unregister_flush (const char *name)
1115 return (plugin_unregister (list_flush, name));
1118 int plugin_unregister_missing (const char *name)
1120 return (plugin_unregister (list_missing, name));
1123 int plugin_unregister_shutdown (const char *name)
1125 return (plugin_unregister (list_shutdown, name));
1128 int plugin_unregister_data_set (const char *name)
1132 if (data_sets == NULL)
1135 if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
1142 } /* int plugin_unregister_data_set */
1144 int plugin_unregister_log (const char *name)
1146 return (plugin_unregister (list_log, name));
1149 int plugin_unregister_notification (const char *name)
1151 return (plugin_unregister (list_notification, name));
1154 void plugin_init_all (void)
1156 const char *chain_name;
1160 /* Init the value cache */
1163 chain_name = global_option_get ("PreCacheChain");
1164 pre_cache_chain = fc_chain_get_by_name (chain_name);
1166 chain_name = global_option_get ("PostCacheChain");
1167 post_cache_chain = fc_chain_get_by_name (chain_name);
1170 if ((list_init == NULL) && (read_heap == NULL))
1173 /* Calling all init callbacks before checking if read callbacks
1174 * are available allows the init callbacks to register the read
1176 le = llist_head (list_init);
1179 callback_func_t *cf;
1180 plugin_init_cb callback;
1181 plugin_ctx_t old_ctx;
1184 old_ctx = plugin_set_ctx (cf->cf_ctx);
1185 callback = cf->cf_callback;
1186 status = (*callback) ();
1187 plugin_set_ctx (old_ctx);
1191 ERROR ("Initialization of plugin `%s' "
1192 "failed with status %i. "
1193 "Plugin will be unloaded.",
1195 /* Plugins that register read callbacks from the init
1196 * callback should take care of appropriate error
1197 * handling themselves. */
1198 /* FIXME: Unload _all_ functions */
1199 plugin_unregister_read (le->key);
1205 /* Start read-threads */
1206 if (read_heap != NULL)
1210 rt = global_option_get ("ReadThreads");
1213 start_read_threads ((num > 0) ? num : 5);
1215 } /* void plugin_init_all */
1217 /* TODO: Rename this function. */
1218 void plugin_read_all (void)
1220 uc_check_timeout ();
1223 } /* void plugin_read_all */
1225 /* Read function called when the `-T' command line argument is given. */
1226 int plugin_read_all_once (void)
1229 int return_status = 0;
1231 if (read_heap == NULL)
1233 NOTICE ("No read-functions are registered.");
1240 plugin_ctx_t old_ctx;
1242 rf = c_heap_get_root (read_heap);
1246 old_ctx = plugin_set_ctx (rf->rf_ctx);
1248 if (rf->rf_type == RF_SIMPLE)
1250 int (*callback) (void);
1252 callback = rf->rf_callback;
1253 status = (*callback) ();
1257 plugin_read_cb callback;
1259 callback = rf->rf_callback;
1260 status = (*callback) (&rf->rf_udata);
1263 plugin_set_ctx (old_ctx);
1267 NOTICE ("read-function of plugin `%s' failed.",
1272 destroy_callback ((void *) rf);
1275 return (return_status);
1276 } /* int plugin_read_all_once */
1278 int plugin_write (const char *plugin, /* {{{ */
1279 const data_set_t *ds, const value_list_t *vl)
1287 if (list_write == NULL)
1292 ds = plugin_get_ds (vl->type);
1295 ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
1305 le = llist_head (list_write);
1308 callback_func_t *cf = le->value;
1309 plugin_write_cb callback;
1311 /* do not switch plugin context; rather keep the context (interval)
1312 * information of the calling read plugin */
1314 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
1315 callback = cf->cf_callback;
1316 status = (*callback) (ds, vl, &cf->cf_udata);
1325 if ((success == 0) && (failure != 0))
1330 else /* plugin != NULL */
1332 callback_func_t *cf;
1333 plugin_write_cb callback;
1335 le = llist_head (list_write);
1338 if (strcasecmp (plugin, le->key) == 0)
1349 /* do not switch plugin context; rather keep the context (interval)
1350 * information of the calling read plugin */
1352 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
1353 callback = cf->cf_callback;
1354 status = (*callback) (ds, vl, &cf->cf_udata);
1358 } /* }}} int plugin_write */
1360 int plugin_flush (const char *plugin, cdtime_t timeout, const char *identifier)
1364 if (list_flush == NULL)
1367 le = llist_head (list_flush);
1370 callback_func_t *cf;
1371 plugin_flush_cb callback;
1372 plugin_ctx_t old_ctx;
1374 if ((plugin != NULL)
1375 && (strcmp (plugin, le->key) != 0))
1382 old_ctx = plugin_set_ctx (cf->cf_ctx);
1383 callback = cf->cf_callback;
1385 (*callback) (timeout, identifier, &cf->cf_udata);
1387 plugin_set_ctx (old_ctx);
1392 } /* int plugin_flush */
1394 void plugin_shutdown_all (void)
1398 stop_read_threads ();
1400 destroy_all_callbacks (&list_init);
1402 pthread_mutex_lock (&read_lock);
1403 llist_destroy (read_list);
1405 pthread_mutex_unlock (&read_lock);
1407 destroy_read_heap ();
1409 plugin_flush (/* plugin = */ NULL,
1411 /* identifier = */ NULL);
1414 if (list_shutdown != NULL)
1415 le = llist_head (list_shutdown);
1419 callback_func_t *cf;
1420 plugin_shutdown_cb callback;
1421 plugin_ctx_t old_ctx;
1424 old_ctx = plugin_set_ctx (cf->cf_ctx);
1425 callback = cf->cf_callback;
1427 /* Advance the pointer before calling the callback allows
1428 * shutdown functions to unregister themselves. If done the
1429 * other way around the memory `le' points to will be freed
1430 * after callback returns. */
1435 plugin_set_ctx (old_ctx);
1438 /* Write plugins which use the `user_data' pointer usually need the
1439 * same data available to the flush callback. If this is the case, set
1440 * the free_function to NULL when registering the flush callback and to
1441 * the real free function when registering the write callback. This way
1442 * the data isn't freed twice. */
1443 destroy_all_callbacks (&list_flush);
1444 destroy_all_callbacks (&list_missing);
1445 destroy_all_callbacks (&list_write);
1447 destroy_all_callbacks (&list_notification);
1448 destroy_all_callbacks (&list_shutdown);
1449 destroy_all_callbacks (&list_log);
1450 } /* void plugin_shutdown_all */
1452 int plugin_dispatch_missing (const value_list_t *vl) /* {{{ */
1456 if (list_missing == NULL)
1459 le = llist_head (list_missing);
1462 callback_func_t *cf;
1463 plugin_missing_cb callback;
1464 plugin_ctx_t old_ctx;
1468 old_ctx = plugin_set_ctx (cf->cf_ctx);
1469 callback = cf->cf_callback;
1471 status = (*callback) (vl, &cf->cf_udata);
1472 plugin_set_ctx (old_ctx);
1477 ERROR ("plugin_dispatch_missing: Callback function \"%s\" "
1478 "failed with status %i.",
1491 } /* int }}} plugin_dispatch_missing */
1493 int plugin_dispatch_values (value_list_t *vl)
1496 static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
1498 value_t *saved_values;
1499 int saved_values_len;
1503 int free_meta_data = 0;
1505 if ((vl == NULL) || (vl->type[0] == 0)
1506 || (vl->values == NULL) || (vl->values_len < 1))
1508 ERROR ("plugin_dispatch_values: Invalid value list "
1509 "from plugin %s.", vl->plugin);
1513 /* Free meta data only if the calling function didn't specify any. In
1514 * this case matches and targets may add some and the calling function
1515 * may not expect (and therefore free) that data. */
1516 if (vl->meta == NULL)
1519 if (list_write == NULL)
1520 c_complain_once (LOG_WARNING, &no_write_complaint,
1521 "plugin_dispatch_values: No write callback has been "
1522 "registered. Please load at least one output plugin, "
1523 "if you want the collected data to be stored.");
1525 if (data_sets == NULL)
1527 ERROR ("plugin_dispatch_values: No data sets registered. "
1528 "Could the types database be read? Check "
1529 "your `TypesDB' setting!");
1533 if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
1535 char ident[6 * DATA_MAX_NAME_LEN];
1537 FORMAT_VL (ident, sizeof (ident), vl);
1538 INFO ("plugin_dispatch_values: Dataset not found: %s "
1539 "(from \"%s\"), check your types.db!",
1545 vl->time = cdtime ();
1547 if (vl->interval <= 0)
1549 plugin_ctx_t ctx = plugin_get_ctx ();
1551 if (ctx.interval != 0)
1552 vl->interval = ctx.interval;
1555 char name[6 * DATA_MAX_NAME_LEN];
1556 FORMAT_VL (name, sizeof (name), vl);
1557 ERROR ("plugin_dispatch_values: Unable to determine "
1558 "interval from context for "
1559 "value list \"%s\". "
1560 "This indicates a broken plugin. "
1561 "Please report this problem to the "
1562 "collectd mailing list or at "
1563 "<http://collectd.org/bugs/>.", name);
1564 vl->interval = cf_get_default_interval ();
1568 DEBUG ("plugin_dispatch_values: time = %.3f; interval = %.3f; "
1570 "plugin = %s; plugin_instance = %s; "
1571 "type = %s; type_instance = %s;",
1572 CDTIME_T_TO_DOUBLE (vl->time),
1573 CDTIME_T_TO_DOUBLE (vl->interval),
1575 vl->plugin, vl->plugin_instance,
1576 vl->type, vl->type_instance);
1579 assert (0 == strcmp (ds->type, vl->type));
1581 if (0 != strcmp (ds->type, vl->type))
1582 WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
1583 ds->type, vl->type);
1587 assert (ds->ds_num == vl->values_len);
1589 if (ds->ds_num != vl->values_len)
1591 ERROR ("plugin_dispatch_values: ds->type = %s: "
1592 "(ds->ds_num = %i) != "
1593 "(vl->values_len = %i)",
1594 ds->type, ds->ds_num, vl->values_len);
1599 escape_slashes (vl->host, sizeof (vl->host));
1600 escape_slashes (vl->plugin, sizeof (vl->plugin));
1601 escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
1602 escape_slashes (vl->type, sizeof (vl->type));
1603 escape_slashes (vl->type_instance, sizeof (vl->type_instance));
1605 /* Copy the values. This way, we can assure `targets' that they get
1606 * dynamically allocated values, which they can free and replace if
1608 if ((pre_cache_chain != NULL) || (post_cache_chain != NULL))
1610 saved_values = vl->values;
1611 saved_values_len = vl->values_len;
1613 vl->values = (value_t *) calloc (vl->values_len,
1614 sizeof (*vl->values));
1615 if (vl->values == NULL)
1617 ERROR ("plugin_dispatch_values: calloc failed.");
1618 vl->values = saved_values;
1621 memcpy (vl->values, saved_values,
1622 vl->values_len * sizeof (*vl->values));
1624 else /* if ((pre == NULL) && (post == NULL)) */
1626 saved_values = NULL;
1627 saved_values_len = 0;
1630 if (pre_cache_chain != NULL)
1632 status = fc_process_chain (ds, vl, pre_cache_chain);
1635 WARNING ("plugin_dispatch_values: Running the "
1636 "pre-cache chain failed with "
1640 else if (status == FC_TARGET_STOP)
1642 /* Restore the state of the value_list so that plugins
1643 * don't get confused.. */
1644 if (saved_values != NULL)
1647 vl->values = saved_values;
1648 vl->values_len = saved_values_len;
1654 /* Update the value cache */
1657 if (post_cache_chain != NULL)
1659 status = fc_process_chain (ds, vl, post_cache_chain);
1662 WARNING ("plugin_dispatch_values: Running the "
1663 "post-cache chain failed with "
1669 fc_default_action (ds, vl);
1671 /* Restore the state of the value_list so that plugins don't get
1673 if (saved_values != NULL)
1676 vl->values = saved_values;
1677 vl->values_len = saved_values_len;
1680 if ((free_meta_data != 0) && (vl->meta != NULL))
1682 meta_data_destroy (vl->meta);
1687 } /* int plugin_dispatch_values */
1689 int plugin_dispatch_values_secure (const value_list_t *vl)
1691 value_list_t vl_copy;
1697 memcpy (&vl_copy, vl, sizeof (vl_copy));
1699 /* Write callbacks must not change the values and meta pointers, so we can
1700 * savely skip copying those and make this more efficient. */
1701 if ((pre_cache_chain == NULL) && (post_cache_chain == NULL))
1702 return (plugin_dispatch_values (&vl_copy));
1704 /* Set pointers to NULL, just to be on the save side. */
1705 vl_copy.values = NULL;
1706 vl_copy.meta = NULL;
1708 vl_copy.values = malloc (sizeof (*vl_copy.values) * vl->values_len);
1709 if (vl_copy.values == NULL)
1711 ERROR ("plugin_dispatch_values_secure: malloc failed.");
1714 memcpy (vl_copy.values, vl->values, sizeof (*vl_copy.values) * vl->values_len);
1716 if (vl->meta != NULL)
1718 vl_copy.meta = meta_data_clone (vl->meta);
1719 if (vl_copy.meta == NULL)
1721 ERROR ("plugin_dispatch_values_secure: meta_data_clone failed.");
1722 free (vl_copy.values);
1725 } /* if (vl->meta) */
1727 status = plugin_dispatch_values (&vl_copy);
1729 meta_data_destroy (vl_copy.meta);
1730 free (vl_copy.values);
1733 } /* int plugin_dispatch_values_secure */
1735 int plugin_dispatch_notification (const notification_t *notif)
1738 /* Possible TODO: Add flap detection here */
1740 DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
1741 "time = %.3f; host = %s;",
1742 notif->severity, notif->message,
1743 CDTIME_T_TO_DOUBLE (notif->time), notif->host);
1745 /* Nobody cares for notifications */
1746 if (list_notification == NULL)
1749 le = llist_head (list_notification);
1752 callback_func_t *cf;
1753 plugin_notification_cb callback;
1756 /* do not switch plugin context; rather keep the context
1757 * (interval) information of the calling plugin */
1760 callback = cf->cf_callback;
1761 status = (*callback) (notif, &cf->cf_udata);
1764 WARNING ("plugin_dispatch_notification: Notification "
1765 "callback %s returned %i.",
1773 } /* int plugin_dispatch_notification */
1775 void plugin_log (int level, const char *format, ...)
1782 if (level >= LOG_DEBUG)
1786 va_start (ap, format);
1787 vsnprintf (msg, sizeof (msg), format, ap);
1788 msg[sizeof (msg) - 1] = '\0';
1791 if (list_log == NULL)
1793 fprintf (stderr, "%s\n", msg);
1797 le = llist_head (list_log);
1800 callback_func_t *cf;
1801 plugin_log_cb callback;
1804 callback = cf->cf_callback;
1806 /* do not switch plugin context; rather keep the context
1807 * (interval) information of the calling plugin */
1809 (*callback) (level, msg, &cf->cf_udata);
1813 } /* void plugin_log */
1815 int parse_log_severity (const char *severity)
1819 if ((0 == strcasecmp (severity, "emerg"))
1820 || (0 == strcasecmp (severity, "alert"))
1821 || (0 == strcasecmp (severity, "crit"))
1822 || (0 == strcasecmp (severity, "err")))
1823 log_level = LOG_ERR;
1824 else if (0 == strcasecmp (severity, "warning"))
1825 log_level = LOG_WARNING;
1826 else if (0 == strcasecmp (severity, "notice"))
1827 log_level = LOG_NOTICE;
1828 else if (0 == strcasecmp (severity, "info"))
1829 log_level = LOG_INFO;
1831 else if (0 == strcasecmp (severity, "debug"))
1832 log_level = LOG_DEBUG;
1833 #endif /* COLLECT_DEBUG */
1836 } /* int parse_log_severity */
1838 int parse_notif_severity (const char *severity)
1840 int notif_severity = -1;
1842 if (strcasecmp (severity, "FAILURE") == 0)
1843 notif_severity = NOTIF_FAILURE;
1844 else if (strcmp (severity, "OKAY") == 0)
1845 notif_severity = NOTIF_OKAY;
1846 else if ((strcmp (severity, "WARNING") == 0)
1847 || (strcmp (severity, "WARN") == 0))
1848 notif_severity = NOTIF_WARNING;
1850 return (notif_severity);
1851 } /* int parse_notif_severity */
1853 const data_set_t *plugin_get_ds (const char *name)
1857 if (c_avl_get (data_sets, name, (void *) &ds) != 0)
1859 DEBUG ("No such dataset registered: %s", name);
1864 } /* data_set_t *plugin_get_ds */
1866 static int plugin_notification_meta_add (notification_t *n,
1868 enum notification_meta_type_e type,
1871 notification_meta_t *meta;
1872 notification_meta_t *tail;
1874 if ((n == NULL) || (name == NULL) || (value == NULL))
1876 ERROR ("plugin_notification_meta_add: A pointer is NULL!");
1880 meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
1883 ERROR ("plugin_notification_meta_add: malloc failed.");
1886 memset (meta, 0, sizeof (notification_meta_t));
1888 sstrncpy (meta->name, name, sizeof (meta->name));
1893 case NM_TYPE_STRING:
1895 meta->nm_value.nm_string = strdup ((const char *) value);
1896 if (meta->nm_value.nm_string == NULL)
1898 ERROR ("plugin_notification_meta_add: strdup failed.");
1904 case NM_TYPE_SIGNED_INT:
1906 meta->nm_value.nm_signed_int = *((int64_t *) value);
1909 case NM_TYPE_UNSIGNED_INT:
1911 meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
1914 case NM_TYPE_DOUBLE:
1916 meta->nm_value.nm_double = *((double *) value);
1919 case NM_TYPE_BOOLEAN:
1921 meta->nm_value.nm_boolean = *((_Bool *) value);
1926 ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
1930 } /* switch (type) */
1934 while ((tail != NULL) && (tail->next != NULL))
1943 } /* int plugin_notification_meta_add */
1945 int plugin_notification_meta_add_string (notification_t *n,
1949 return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
1952 int plugin_notification_meta_add_signed_int (notification_t *n,
1956 return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
1959 int plugin_notification_meta_add_unsigned_int (notification_t *n,
1963 return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
1966 int plugin_notification_meta_add_double (notification_t *n,
1970 return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
1973 int plugin_notification_meta_add_boolean (notification_t *n,
1977 return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
1980 int plugin_notification_meta_copy (notification_t *dst,
1981 const notification_t *src)
1983 notification_meta_t *meta;
1985 assert (dst != NULL);
1986 assert (src != NULL);
1987 assert (dst != src);
1988 assert ((src->meta == NULL) || (src->meta != dst->meta));
1990 for (meta = src->meta; meta != NULL; meta = meta->next)
1992 if (meta->type == NM_TYPE_STRING)
1993 plugin_notification_meta_add_string (dst, meta->name,
1994 meta->nm_value.nm_string);
1995 else if (meta->type == NM_TYPE_SIGNED_INT)
1996 plugin_notification_meta_add_signed_int (dst, meta->name,
1997 meta->nm_value.nm_signed_int);
1998 else if (meta->type == NM_TYPE_UNSIGNED_INT)
1999 plugin_notification_meta_add_unsigned_int (dst, meta->name,
2000 meta->nm_value.nm_unsigned_int);
2001 else if (meta->type == NM_TYPE_DOUBLE)
2002 plugin_notification_meta_add_double (dst, meta->name,
2003 meta->nm_value.nm_double);
2004 else if (meta->type == NM_TYPE_BOOLEAN)
2005 plugin_notification_meta_add_boolean (dst, meta->name,
2006 meta->nm_value.nm_boolean);
2010 } /* int plugin_notification_meta_copy */
2012 int plugin_notification_meta_free (notification_meta_t *n)
2014 notification_meta_t *this;
2015 notification_meta_t *next;
2019 ERROR ("plugin_notification_meta_free: n == NULL!");
2024 while (this != NULL)
2028 if (this->type == NM_TYPE_STRING)
2030 free ((char *)this->nm_value.nm_string);
2031 this->nm_value.nm_string = NULL;
2039 } /* int plugin_notification_meta_free */
2041 static void plugin_ctx_destructor (void *ctx)
2044 } /* void plugin_ctx_destructor */
2046 static plugin_ctx_t ctx_init = { /* interval = */ 0 };
2048 static plugin_ctx_t *plugin_ctx_create (void)
2052 ctx = malloc (sizeof (*ctx));
2055 ERROR ("Failed to allocate plugin context: %s",
2056 sstrerror (errno, errbuf, sizeof (errbuf)));
2061 assert (plugin_ctx_key_initialized);
2062 pthread_setspecific (plugin_ctx_key, ctx);
2063 DEBUG("Created new plugin context.");
2065 } /* int plugin_ctx_create */
2067 void plugin_init_ctx (void)
2069 pthread_key_create (&plugin_ctx_key, plugin_ctx_destructor);
2070 plugin_ctx_key_initialized = 1;
2071 } /* void plugin_init_ctx */
2073 plugin_ctx_t plugin_get_ctx (void)
2077 assert (plugin_ctx_key_initialized);
2078 ctx = pthread_getspecific (plugin_ctx_key);
2081 ctx = plugin_ctx_create ();
2082 /* this must no happen -- exit() instead? */
2088 } /* plugin_ctx_t plugin_get_ctx */
2090 plugin_ctx_t plugin_set_ctx (plugin_ctx_t ctx)
2095 assert (plugin_ctx_key_initialized);
2096 c = pthread_getspecific (plugin_ctx_key);
2099 c = plugin_ctx_create ();
2100 /* this must no happen -- exit() instead? */
2109 } /* void plugin_set_ctx */
2111 cdtime_t plugin_get_interval (void)
2115 interval = plugin_get_ctx().interval;
2119 return cf_get_default_interval ();
2120 } /* cdtime_t plugin_get_interval */
2124 void *(*start_routine) (void *);
2128 static void *plugin_thread_start (void *arg)
2130 plugin_thread_t *plugin_thread = arg;
2132 void *(*start_routine) (void *) = plugin_thread->start_routine;
2133 void *plugin_arg = plugin_thread->arg;
2135 plugin_set_ctx (plugin_thread->ctx);
2137 free (plugin_thread);
2139 return start_routine (plugin_arg);
2140 } /* void *plugin_thread_start */
2142 int plugin_thread_create (pthread_t *thread, const pthread_attr_t *attr,
2143 void *(*start_routine) (void *), void *arg)
2145 plugin_thread_t *plugin_thread;
2147 plugin_thread = malloc (sizeof (*plugin_thread));
2148 if (plugin_thread == NULL)
2151 plugin_thread->ctx = plugin_get_ctx ();
2152 plugin_thread->start_routine = start_routine;
2153 plugin_thread->arg = arg;
2155 return pthread_create (thread, attr,
2156 plugin_thread_start, plugin_thread);
2157 } /* int plugin_thread_create */
2159 /* vim: set sw=8 ts=8 noet fdm=marker : */