307bbf4f733bffe9a22cca2de5b71f6981f343b1
1 /**
2 * collectd - src/plugin.c
3 * Copyright (C) 2005-2009 Florian octo Forster
4 *
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.
8 *
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.
13 *
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
17 *
18 * Authors:
19 * Florian octo Forster <octo at verplant.org>
20 * Sebastian Harl <sh at tokkee.org>
21 **/
23 #include "collectd.h"
24 #include "utils_complain.h"
26 #include <ltdl.h>
28 #if HAVE_PTHREAD_H
29 # include <pthread.h>
30 #endif
32 #include "common.h"
33 #include "plugin.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 "utils_threshold.h"
40 #include "filter_chain.h"
42 /*
43 * Private structures
44 */
45 struct callback_func_s
46 {
47 void *cf_callback;
48 user_data_t cf_udata;
49 };
50 typedef struct callback_func_s callback_func_t;
52 #define RF_SIMPLE 0
53 #define RF_COMPLEX 1
54 #define RF_REMOVE 65535
55 struct read_func_s
56 {
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 callback_func_t rf_super;
62 char rf_name[DATA_MAX_NAME_LEN];
63 int rf_type;
64 struct timespec rf_interval;
65 struct timespec rf_effective_interval;
66 struct timespec rf_next_read;
67 };
68 typedef struct read_func_s read_func_t;
70 /*
71 * Private variables
72 */
73 static llist_t *list_init;
74 static llist_t *list_write;
75 static llist_t *list_flush;
76 static llist_t *list_shutdown;
77 static llist_t *list_log;
78 static llist_t *list_notification;
80 static fc_chain_t *pre_cache_chain = NULL;
81 static fc_chain_t *post_cache_chain = NULL;
83 static c_avl_tree_t *data_sets;
85 static char *plugindir = NULL;
87 static c_heap_t *read_heap = NULL;
88 static llist_t *read_list;
89 static int read_loop = 1;
90 static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
91 static pthread_cond_t read_cond = PTHREAD_COND_INITIALIZER;
92 static pthread_t *read_threads = NULL;
93 static int read_threads_num = 0;
95 /*
96 * Static functions
97 */
98 static const char *plugin_get_dir (void)
99 {
100 if (plugindir == NULL)
101 return (PLUGINDIR);
102 else
103 return (plugindir);
104 }
106 static void destroy_callback (callback_func_t *cf) /* {{{ */
107 {
108 if (cf == NULL)
109 return;
111 if ((cf->cf_udata.data != NULL) && (cf->cf_udata.free_func != NULL))
112 {
113 cf->cf_udata.free_func (cf->cf_udata.data);
114 cf->cf_udata.data = NULL;
115 cf->cf_udata.free_func = NULL;
116 }
117 sfree (cf);
118 } /* }}} void destroy_callback */
120 static void destroy_all_callbacks (llist_t **list) /* {{{ */
121 {
122 llentry_t *le;
124 if (*list == NULL)
125 return;
127 le = llist_head (*list);
128 while (le != NULL)
129 {
130 llentry_t *le_next;
132 le_next = le->next;
134 sfree (le->key);
135 destroy_callback (le->value);
136 le->value = NULL;
138 le = le_next;
139 }
141 llist_destroy (*list);
142 *list = NULL;
143 } /* }}} void destroy_all_callbacks */
145 static void destroy_read_heap (void) /* {{{ */
146 {
147 if (read_heap == NULL)
148 return;
150 while (42)
151 {
152 callback_func_t *cf;
154 cf = c_heap_get_root (read_heap);
155 if (cf == NULL)
156 break;
158 destroy_callback (cf);
159 }
161 c_heap_destroy (read_heap);
162 read_heap = NULL;
163 } /* }}} void destroy_read_heap */
165 static int register_callback (llist_t **list, /* {{{ */
166 const char *name, callback_func_t *cf)
167 {
168 llentry_t *le;
169 char *key;
171 if (*list == NULL)
172 {
173 *list = llist_create ();
174 if (*list == NULL)
175 {
176 ERROR ("plugin: register_callback: "
177 "llist_create failed.");
178 destroy_callback (cf);
179 return (-1);
180 }
181 }
183 key = strdup (name);
184 if (key == NULL)
185 {
186 ERROR ("plugin: register_callback: strdup failed.");
187 destroy_callback (cf);
188 return (-1);
189 }
191 le = llist_search (*list, name);
192 if (le == NULL)
193 {
194 le = llentry_create (key, cf);
195 if (le == NULL)
196 {
197 ERROR ("plugin: register_callback: "
198 "llentry_create failed.");
199 free (key);
200 destroy_callback (cf);
201 return (-1);
202 }
204 llist_append (*list, le);
205 }
206 else
207 {
208 callback_func_t *old_cf;
210 old_cf = le->value;
211 le->value = cf;
213 WARNING ("plugin: register_callback: "
214 "a callback named `%s' already exists - "
215 "overwriting the old entry!", name);
217 destroy_callback (old_cf);
218 sfree (key);
219 }
221 return (0);
222 } /* }}} int register_callback */
224 static int create_register_callback (llist_t **list, /* {{{ */
225 const char *name, void *callback, user_data_t *ud)
226 {
227 callback_func_t *cf;
229 cf = (callback_func_t *) malloc (sizeof (*cf));
230 if (cf == NULL)
231 {
232 ERROR ("plugin: create_register_callback: malloc failed.");
233 return (-1);
234 }
235 memset (cf, 0, sizeof (*cf));
237 cf->cf_callback = callback;
238 if (ud == NULL)
239 {
240 cf->cf_udata.data = NULL;
241 cf->cf_udata.free_func = NULL;
242 }
243 else
244 {
245 cf->cf_udata = *ud;
246 }
248 return (register_callback (list, name, cf));
249 } /* }}} int create_register_callback */
251 static int plugin_unregister (llist_t *list, const char *name) /* {{{ */
252 {
253 llentry_t *e;
255 if (list == NULL)
256 return (-1);
258 e = llist_search (list, name);
259 if (e == NULL)
260 return (-1);
262 llist_remove (list, e);
264 sfree (e->key);
265 destroy_callback (e->value);
267 llentry_destroy (e);
269 return (0);
270 } /* }}} int plugin_unregister */
272 /*
273 * (Try to) load the shared object `file'. Won't complain if it isn't a shared
274 * object, but it will bitch about a shared object not having a
275 * ``module_register'' symbol..
276 */
277 static int plugin_load_file (char *file, uint32_t flags)
278 {
279 lt_dlhandle dlh;
280 void (*reg_handle) (void);
282 DEBUG ("file = %s", file);
284 lt_dlinit ();
285 lt_dlerror (); /* clear errors */
287 #if LIBTOOL_VERSION == 2
288 if (flags & PLUGIN_FLAGS_GLOBAL) {
289 lt_dladvise advise;
290 lt_dladvise_init(&advise);
291 lt_dladvise_global(&advise);
292 dlh = lt_dlopenadvise(file, advise);
293 lt_dladvise_destroy(&advise);
294 } else {
295 dlh = lt_dlopen (file);
296 }
297 #else /* if LIBTOOL_VERSION == 1 */
298 if (flags & PLUGIN_FLAGS_GLOBAL)
299 ERROR ("plugin_load_file: The global flag is not supported, "
300 "libtool 2 is required for this.");
301 dlh = lt_dlopen (file);
302 #endif
304 if (dlh == NULL)
305 {
306 const char *error = lt_dlerror ();
308 ERROR ("lt_dlopen (%s) failed: %s", file, error);
309 fprintf (stderr, "lt_dlopen (%s) failed: %s\n", file, error);
310 return (1);
311 }
313 if ((reg_handle = (void (*) (void)) lt_dlsym (dlh, "module_register")) == NULL)
314 {
315 WARNING ("Couldn't find symbol `module_register' in `%s': %s\n",
316 file, lt_dlerror ());
317 lt_dlclose (dlh);
318 return (-1);
319 }
321 (*reg_handle) ();
323 return (0);
324 }
326 static _Bool timeout_reached(struct timespec timeout)
327 {
328 struct timeval now;
329 gettimeofday(&now, NULL);
330 return (now.tv_sec >= timeout.tv_sec && now.tv_usec >= (timeout.tv_nsec / 1000));
331 }
333 static void *plugin_read_thread (void __attribute__((unused)) *args)
334 {
335 while (read_loop != 0)
336 {
337 read_func_t *rf;
338 struct timeval now;
339 int status;
340 int rf_type;
341 int rc;
343 /* Get the read function that needs to be read next. */
344 rf = c_heap_get_root (read_heap);
345 if (rf == NULL)
346 {
347 struct timespec abstime;
349 gettimeofday (&now, /* timezone = */ NULL);
351 abstime.tv_sec = now.tv_sec + interval_g;
352 abstime.tv_nsec = 1000 * now.tv_usec;
354 pthread_mutex_lock (&read_lock);
355 pthread_cond_timedwait (&read_cond, &read_lock,
356 &abstime);
357 pthread_mutex_unlock (&read_lock);
358 continue;
359 }
361 if ((rf->rf_interval.tv_sec == 0) && (rf->rf_interval.tv_nsec == 0))
362 {
363 gettimeofday (&now, /* timezone = */ NULL);
365 rf->rf_interval.tv_sec = interval_g;
366 rf->rf_interval.tv_nsec = 0;
368 rf->rf_effective_interval = rf->rf_interval;
370 rf->rf_next_read.tv_sec = now.tv_sec;
371 rf->rf_next_read.tv_nsec = 1000 * now.tv_usec;
372 }
374 /* sleep until this entry is due,
375 * using pthread_cond_timedwait */
376 pthread_mutex_lock (&read_lock);
377 /* In pthread_cond_timedwait, spurious wakeups are possible
378 * (and really happen, at least on NetBSD with > 1 CPU), thus
379 * we need to re-evaluate the condition every time
380 * pthread_cond_timedwait returns. */
381 rc = 0;
382 while ((read_loop != 0)
383 && !timeout_reached(rf->rf_next_read)
384 && rc == 0)
385 {
386 rc = pthread_cond_timedwait (&read_cond, &read_lock,
387 &rf->rf_next_read);
388 }
390 /* Must hold `read_lock' when accessing `rf->rf_type'. */
391 rf_type = rf->rf_type;
392 pthread_mutex_unlock (&read_lock);
394 /* Check if we're supposed to stop.. This may have interrupted
395 * the sleep, too. */
396 if (read_loop == 0)
397 {
398 /* Insert `rf' again, so it can be free'd correctly */
399 c_heap_insert (read_heap, rf);
400 break;
401 }
403 /* The entry has been marked for deletion. The linked list
404 * entry has already been removed by `plugin_unregister_read'.
405 * All we have to do here is free the `read_func_t' and
406 * continue. */
407 if (rf_type == RF_REMOVE)
408 {
409 DEBUG ("plugin_read_thread: Destroying the `%s' "
410 "callback.", rf->rf_name);
411 destroy_callback ((callback_func_t *) rf);
412 rf = NULL;
413 continue;
414 }
416 DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
418 if (rf_type == RF_SIMPLE)
419 {
420 int (*callback) (void);
422 callback = rf->rf_callback;
423 status = (*callback) ();
424 }
425 else
426 {
427 plugin_read_cb callback;
429 assert (rf_type == RF_COMPLEX);
431 callback = rf->rf_callback;
432 status = (*callback) (&rf->rf_udata);
433 }
435 /* If the function signals failure, we will increase the
436 * intervals in which it will be called. */
437 if (status != 0)
438 {
439 rf->rf_effective_interval.tv_sec *= 2;
440 rf->rf_effective_interval.tv_nsec *= 2;
441 NORMALIZE_TIMESPEC (rf->rf_effective_interval);
443 if (rf->rf_effective_interval.tv_sec >= 86400)
444 {
445 rf->rf_effective_interval.tv_sec = 86400;
446 rf->rf_effective_interval.tv_nsec = 0;
447 }
449 NOTICE ("read-function of plugin `%s' failed. "
450 "Will suspend it for %i seconds.",
451 rf->rf_name,
452 (int) rf->rf_effective_interval.tv_sec);
453 }
454 else
455 {
456 /* Success: Restore the interval, if it was changed. */
457 rf->rf_effective_interval = rf->rf_interval;
458 }
460 /* update the ``next read due'' field */
461 gettimeofday (&now, /* timezone = */ NULL);
463 DEBUG ("plugin_read_thread: Effective interval of the "
464 "%s plugin is %i.%09i.",
465 rf->rf_name,
466 (int) rf->rf_effective_interval.tv_sec,
467 (int) rf->rf_effective_interval.tv_nsec);
469 /* Calculate the next (absolute) time at which this function
470 * should be called. */
471 rf->rf_next_read.tv_sec = rf->rf_next_read.tv_sec
472 + rf->rf_effective_interval.tv_sec;
473 rf->rf_next_read.tv_nsec = rf->rf_next_read.tv_nsec
474 + rf->rf_effective_interval.tv_nsec;
475 NORMALIZE_TIMESPEC (rf->rf_next_read);
477 /* Check, if `rf_next_read' is in the past. */
478 if ((rf->rf_next_read.tv_sec < now.tv_sec)
479 || ((rf->rf_next_read.tv_sec == now.tv_sec)
480 && (rf->rf_next_read.tv_nsec < (1000 * now.tv_usec))))
481 {
482 /* `rf_next_read' is in the past. Insert `now'
483 * so this value doesn't trail off into the
484 * past too much. */
485 rf->rf_next_read.tv_sec = now.tv_sec;
486 rf->rf_next_read.tv_nsec = 1000 * now.tv_usec;
487 }
489 DEBUG ("plugin_read_thread: Next read of the %s plugin at %i.%09i.",
490 rf->rf_name,
491 (int) rf->rf_next_read.tv_sec,
492 (int) rf->rf_next_read.tv_nsec);
494 /* Re-insert this read function into the heap again. */
495 c_heap_insert (read_heap, rf);
496 } /* while (read_loop) */
498 pthread_exit (NULL);
499 return ((void *) 0);
500 } /* void *plugin_read_thread */
502 static void start_read_threads (int num)
503 {
504 int i;
506 if (read_threads != NULL)
507 return;
509 read_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
510 if (read_threads == NULL)
511 {
512 ERROR ("plugin: start_read_threads: calloc failed.");
513 return;
514 }
516 read_threads_num = 0;
517 for (i = 0; i < num; i++)
518 {
519 if (pthread_create (read_threads + read_threads_num, NULL,
520 plugin_read_thread, NULL) == 0)
521 {
522 read_threads_num++;
523 }
524 else
525 {
526 ERROR ("plugin: start_read_threads: pthread_create failed.");
527 return;
528 }
529 } /* for (i) */
530 } /* void start_read_threads */
532 static void stop_read_threads (void)
533 {
534 int i;
536 if (read_threads == NULL)
537 return;
539 INFO ("collectd: Stopping %i read threads.", read_threads_num);
541 pthread_mutex_lock (&read_lock);
542 read_loop = 0;
543 DEBUG ("plugin: stop_read_threads: Signalling `read_cond'");
544 pthread_cond_broadcast (&read_cond);
545 pthread_mutex_unlock (&read_lock);
547 for (i = 0; i < read_threads_num; i++)
548 {
549 if (pthread_join (read_threads[i], NULL) != 0)
550 {
551 ERROR ("plugin: stop_read_threads: pthread_join failed.");
552 }
553 read_threads[i] = (pthread_t) 0;
554 }
555 sfree (read_threads);
556 read_threads_num = 0;
557 } /* void stop_read_threads */
559 /*
560 * Public functions
561 */
562 void plugin_set_dir (const char *dir)
563 {
564 if (plugindir != NULL)
565 free (plugindir);
567 if (dir == NULL)
568 plugindir = NULL;
569 else if ((plugindir = strdup (dir)) == NULL)
570 {
571 char errbuf[1024];
572 ERROR ("strdup failed: %s",
573 sstrerror (errno, errbuf, sizeof (errbuf)));
574 }
575 }
577 #define BUFSIZE 512
578 int plugin_load (const char *type, uint32_t flags)
579 {
580 DIR *dh;
581 const char *dir;
582 char filename[BUFSIZE] = "";
583 char typename[BUFSIZE];
584 int typename_len;
585 int ret;
586 struct stat statbuf;
587 struct dirent *de;
588 int status;
590 DEBUG ("type = %s", type);
592 dir = plugin_get_dir ();
593 ret = 1;
595 /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
596 * type when matching the filename */
597 status = ssnprintf (typename, sizeof (typename), "%s.so", type);
598 if ((status < 0) || ((size_t) status >= sizeof (typename)))
599 {
600 WARNING ("snprintf: truncated: `%s.so'", type);
601 return (-1);
602 }
603 typename_len = strlen (typename);
605 if ((dh = opendir (dir)) == NULL)
606 {
607 char errbuf[1024];
608 ERROR ("opendir (%s): %s", dir,
609 sstrerror (errno, errbuf, sizeof (errbuf)));
610 return (-1);
611 }
613 while ((de = readdir (dh)) != NULL)
614 {
615 if (strncasecmp (de->d_name, typename, typename_len))
616 continue;
618 status = ssnprintf (filename, sizeof (filename),
619 "%s/%s", dir, de->d_name);
620 if ((status < 0) || ((size_t) status >= sizeof (filename)))
621 {
622 WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name);
623 continue;
624 }
626 if (lstat (filename, &statbuf) == -1)
627 {
628 char errbuf[1024];
629 WARNING ("stat %s: %s", filename,
630 sstrerror (errno, errbuf, sizeof (errbuf)));
631 continue;
632 }
633 else if (!S_ISREG (statbuf.st_mode))
634 {
635 /* don't follow symlinks */
636 WARNING ("stat %s: not a regular file", filename);
637 continue;
638 }
640 if (plugin_load_file (filename, flags) == 0)
641 {
642 /* success */
643 ret = 0;
644 break;
645 }
646 else
647 {
648 fprintf (stderr, "Unable to load plugin %s.\n", type);
649 }
650 }
652 closedir (dh);
654 if (filename[0] == '\0')
655 fprintf (stderr, "Could not find plugin %s.\n", type);
657 return (ret);
658 }
660 /*
661 * The `register_*' functions follow
662 */
663 int plugin_register_config (const char *name,
664 int (*callback) (const char *key, const char *val),
665 const char **keys, int keys_num)
666 {
667 cf_register (name, callback, keys, keys_num);
668 return (0);
669 } /* int plugin_register_config */
671 int plugin_register_complex_config (const char *type,
672 int (*callback) (oconfig_item_t *))
673 {
674 return (cf_register_complex (type, callback));
675 } /* int plugin_register_complex_config */
677 int plugin_register_init (const char *name,
678 int (*callback) (void))
679 {
680 return (create_register_callback (&list_init, name, (void *) callback,
681 /* user_data = */ NULL));
682 } /* plugin_register_init */
684 static int plugin_compare_read_func (const void *arg0, const void *arg1)
685 {
686 const read_func_t *rf0;
687 const read_func_t *rf1;
689 rf0 = arg0;
690 rf1 = arg1;
692 if (rf0->rf_next_read.tv_sec < rf1->rf_next_read.tv_sec)
693 return (-1);
694 else if (rf0->rf_next_read.tv_sec > rf1->rf_next_read.tv_sec)
695 return (1);
696 else if (rf0->rf_next_read.tv_nsec < rf1->rf_next_read.tv_nsec)
697 return (-1);
698 else if (rf0->rf_next_read.tv_nsec > rf1->rf_next_read.tv_nsec)
699 return (1);
700 else
701 return (0);
702 } /* int plugin_compare_read_func */
704 /* Add a read function to both, the heap and a linked list. The linked list if
705 * used to look-up read functions, especially for the remove function. The heap
706 * is used to determine which plugin to read next. */
707 static int plugin_insert_read (read_func_t *rf)
708 {
709 int status;
710 llentry_t *le;
712 pthread_mutex_lock (&read_lock);
714 if (read_list == NULL)
715 {
716 read_list = llist_create ();
717 if (read_list == NULL)
718 {
719 pthread_mutex_unlock (&read_lock);
720 ERROR ("plugin_insert_read: read_list failed.");
721 return (-1);
722 }
723 }
725 if (read_heap == NULL)
726 {
727 read_heap = c_heap_create (plugin_compare_read_func);
728 if (read_heap == NULL)
729 {
730 pthread_mutex_unlock (&read_lock);
731 ERROR ("plugin_insert_read: c_heap_create failed.");
732 return (-1);
733 }
734 }
736 le = llentry_create (rf->rf_name, rf);
737 if (le == NULL)
738 {
739 pthread_mutex_unlock (&read_lock);
740 ERROR ("plugin_insert_read: llentry_create failed.");
741 return (-1);
742 }
744 status = c_heap_insert (read_heap, rf);
745 if (status != 0)
746 {
747 pthread_mutex_unlock (&read_lock);
748 ERROR ("plugin_insert_read: c_heap_insert failed.");
749 llentry_destroy (le);
750 return (-1);
751 }
753 /* This does not fail. */
754 llist_append (read_list, le);
756 pthread_mutex_unlock (&read_lock);
757 return (0);
758 } /* int plugin_insert_read */
760 int plugin_register_read (const char *name,
761 int (*callback) (void))
762 {
763 read_func_t *rf;
765 rf = (read_func_t *) malloc (sizeof (read_func_t));
766 if (rf == NULL)
767 {
768 char errbuf[1024];
769 ERROR ("plugin_register_read: malloc failed: %s",
770 sstrerror (errno, errbuf, sizeof (errbuf)));
771 return (-1);
772 }
774 memset (rf, 0, sizeof (read_func_t));
775 rf->rf_callback = (void *) callback;
776 rf->rf_udata.data = NULL;
777 rf->rf_udata.free_func = NULL;
778 sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
779 rf->rf_type = RF_SIMPLE;
780 rf->rf_interval.tv_sec = 0;
781 rf->rf_interval.tv_nsec = 0;
782 rf->rf_effective_interval = rf->rf_interval;
784 return (plugin_insert_read (rf));
785 } /* int plugin_register_read */
787 int plugin_register_complex_read (const char *name,
788 plugin_read_cb callback,
789 const struct timespec *interval,
790 user_data_t *user_data)
791 {
792 read_func_t *rf;
794 rf = (read_func_t *) malloc (sizeof (read_func_t));
795 if (rf == NULL)
796 {
797 ERROR ("plugin_register_complex_read: malloc failed.");
798 return (-1);
799 }
801 memset (rf, 0, sizeof (read_func_t));
802 rf->rf_callback = (void *) callback;
803 sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
804 rf->rf_type = RF_COMPLEX;
805 if (interval != NULL)
806 {
807 rf->rf_interval = *interval;
808 }
809 rf->rf_effective_interval = rf->rf_interval;
811 /* Set user data */
812 if (user_data == NULL)
813 {
814 rf->rf_udata.data = NULL;
815 rf->rf_udata.free_func = NULL;
816 }
817 else
818 {
819 rf->rf_udata = *user_data;
820 }
822 return (plugin_insert_read (rf));
823 } /* int plugin_register_complex_read */
825 int plugin_register_write (const char *name,
826 plugin_write_cb callback, user_data_t *ud)
827 {
828 return (create_register_callback (&list_write, name,
829 (void *) callback, ud));
830 } /* int plugin_register_write */
832 int plugin_register_flush (const char *name,
833 plugin_flush_cb callback, user_data_t *ud)
834 {
835 return (create_register_callback (&list_flush, name,
836 (void *) callback, ud));
837 } /* int plugin_register_flush */
839 int plugin_register_shutdown (char *name,
840 int (*callback) (void))
841 {
842 return (create_register_callback (&list_shutdown, name,
843 (void *) callback, /* user_data = */ NULL));
844 } /* int plugin_register_shutdown */
846 int plugin_register_data_set (const data_set_t *ds)
847 {
848 data_set_t *ds_copy;
849 int i;
851 if ((data_sets != NULL)
852 && (c_avl_get (data_sets, ds->type, NULL) == 0))
853 {
854 NOTICE ("Replacing DS `%s' with another version.", ds->type);
855 plugin_unregister_data_set (ds->type);
856 }
857 else if (data_sets == NULL)
858 {
859 data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
860 if (data_sets == NULL)
861 return (-1);
862 }
864 ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
865 if (ds_copy == NULL)
866 return (-1);
867 memcpy(ds_copy, ds, sizeof (data_set_t));
869 ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
870 * ds->ds_num);
871 if (ds_copy->ds == NULL)
872 {
873 free (ds_copy);
874 return (-1);
875 }
877 for (i = 0; i < ds->ds_num; i++)
878 memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
880 return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
881 } /* int plugin_register_data_set */
883 int plugin_register_log (const char *name,
884 plugin_log_cb callback, user_data_t *ud)
885 {
886 return (create_register_callback (&list_log, name,
887 (void *) callback, ud));
888 } /* int plugin_register_log */
890 int plugin_register_notification (const char *name,
891 plugin_notification_cb callback, user_data_t *ud)
892 {
893 return (create_register_callback (&list_notification, name,
894 (void *) callback, ud));
895 } /* int plugin_register_log */
897 int plugin_unregister_config (const char *name)
898 {
899 cf_unregister (name);
900 return (0);
901 } /* int plugin_unregister_config */
903 int plugin_unregister_complex_config (const char *name)
904 {
905 cf_unregister_complex (name);
906 return (0);
907 } /* int plugin_unregister_complex_config */
909 int plugin_unregister_init (const char *name)
910 {
911 return (plugin_unregister (list_init, name));
912 }
914 int plugin_unregister_read (const char *name) /* {{{ */
915 {
916 llentry_t *le;
917 read_func_t *rf;
919 if (name == NULL)
920 return (-ENOENT);
922 pthread_mutex_lock (&read_lock);
924 if (read_list == NULL)
925 {
926 pthread_mutex_unlock (&read_lock);
927 return (-ENOENT);
928 }
930 le = llist_search (read_list, name);
931 if (le == NULL)
932 {
933 pthread_mutex_unlock (&read_lock);
934 WARNING ("plugin_unregister_read: No such read function: %s",
935 name);
936 return (-ENOENT);
937 }
939 llist_remove (read_list, le);
941 rf = le->value;
942 assert (rf != NULL);
943 rf->rf_type = RF_REMOVE;
945 pthread_mutex_unlock (&read_lock);
947 llentry_destroy (le);
949 DEBUG ("plugin_unregister_read: Marked `%s' for removal.", name);
951 return (0);
952 } /* }}} int plugin_unregister_read */
954 int plugin_unregister_write (const char *name)
955 {
956 return (plugin_unregister (list_write, name));
957 }
959 int plugin_unregister_flush (const char *name)
960 {
961 return (plugin_unregister (list_flush, name));
962 }
964 int plugin_unregister_shutdown (const char *name)
965 {
966 return (plugin_unregister (list_shutdown, name));
967 }
969 int plugin_unregister_data_set (const char *name)
970 {
971 data_set_t *ds;
973 if (data_sets == NULL)
974 return (-1);
976 if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
977 return (-1);
979 sfree (ds->ds);
980 sfree (ds);
982 return (0);
983 } /* int plugin_unregister_data_set */
985 int plugin_unregister_log (const char *name)
986 {
987 return (plugin_unregister (list_log, name));
988 }
990 int plugin_unregister_notification (const char *name)
991 {
992 return (plugin_unregister (list_notification, name));
993 }
995 void plugin_init_all (void)
996 {
997 const char *chain_name;
998 llentry_t *le;
999 int status;
1001 /* Init the value cache */
1002 uc_init ();
1004 chain_name = global_option_get ("PreCacheChain");
1005 pre_cache_chain = fc_chain_get_by_name (chain_name);
1007 chain_name = global_option_get ("PostCacheChain");
1008 post_cache_chain = fc_chain_get_by_name (chain_name);
1011 if ((list_init == NULL) && (read_heap == NULL))
1012 return;
1014 /* Calling all init callbacks before checking if read callbacks
1015 * are available allows the init callbacks to register the read
1016 * callback. */
1017 le = llist_head (list_init);
1018 while (le != NULL)
1019 {
1020 callback_func_t *cf;
1021 plugin_init_cb callback;
1023 cf = le->value;
1024 callback = cf->cf_callback;
1025 status = (*callback) ();
1027 if (status != 0)
1028 {
1029 ERROR ("Initialization of plugin `%s' "
1030 "failed with status %i. "
1031 "Plugin will be unloaded.",
1032 le->key, status);
1033 /* Plugins that register read callbacks from the init
1034 * callback should take care of appropriate error
1035 * handling themselves. */
1036 /* FIXME: Unload _all_ functions */
1037 plugin_unregister_read (le->key);
1038 }
1040 le = le->next;
1041 }
1043 /* Start read-threads */
1044 if (read_heap != NULL)
1045 {
1046 const char *rt;
1047 int num;
1048 rt = global_option_get ("ReadThreads");
1049 num = atoi (rt);
1050 if (num != -1)
1051 start_read_threads ((num > 0) ? num : 5);
1052 }
1053 } /* void plugin_init_all */
1055 /* TODO: Rename this function. */
1056 void plugin_read_all (void)
1057 {
1058 uc_check_timeout ();
1060 return;
1061 } /* void plugin_read_all */
1063 /* Read function called when the `-T' command line argument is given. */
1064 int plugin_read_all_once (void)
1065 {
1066 int status;
1067 int return_status = 0;
1069 if (read_heap == NULL)
1070 {
1071 NOTICE ("No read-functions are registered.");
1072 return (0);
1073 }
1075 while (42)
1076 {
1077 read_func_t *rf;
1079 rf = c_heap_get_root (read_heap);
1080 if (rf == NULL)
1081 break;
1083 if (rf->rf_type == RF_SIMPLE)
1084 {
1085 int (*callback) (void);
1087 callback = rf->rf_callback;
1088 status = (*callback) ();
1089 }
1090 else
1091 {
1092 plugin_read_cb callback;
1094 callback = rf->rf_callback;
1095 status = (*callback) (&rf->rf_udata);
1096 }
1098 if (status != 0)
1099 {
1100 NOTICE ("read-function of plugin `%s' failed.",
1101 rf->rf_name);
1102 return_status = -1;
1103 }
1105 destroy_callback ((void *) rf);
1106 }
1108 return (return_status);
1109 } /* int plugin_read_all_once */
1111 int plugin_write (const char *plugin, /* {{{ */
1112 const data_set_t *ds, const value_list_t *vl)
1113 {
1114 llentry_t *le;
1115 int status;
1117 if (vl == NULL)
1118 return (EINVAL);
1120 if (list_write == NULL)
1121 return (ENOENT);
1123 if (ds == NULL)
1124 {
1125 ds = plugin_get_ds (vl->type);
1126 if (ds == NULL)
1127 {
1128 ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
1129 return (ENOENT);
1130 }
1131 }
1133 if (plugin == NULL)
1134 {
1135 int success = 0;
1136 int failure = 0;
1138 le = llist_head (list_write);
1139 while (le != NULL)
1140 {
1141 callback_func_t *cf = le->value;
1142 plugin_write_cb callback;
1144 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
1145 callback = cf->cf_callback;
1146 status = (*callback) (ds, vl, &cf->cf_udata);
1147 if (status != 0)
1148 failure++;
1149 else
1150 success++;
1152 le = le->next;
1153 }
1155 if ((success == 0) && (failure != 0))
1156 status = -1;
1157 else
1158 status = 0;
1159 }
1160 else /* plugin != NULL */
1161 {
1162 callback_func_t *cf;
1163 plugin_write_cb callback;
1165 le = llist_head (list_write);
1166 while (le != NULL)
1167 {
1168 if (strcasecmp (plugin, le->key) == 0)
1169 break;
1171 le = le->next;
1172 }
1174 if (le == NULL)
1175 return (ENOENT);
1177 cf = le->value;
1179 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
1180 callback = cf->cf_callback;
1181 status = (*callback) (ds, vl, &cf->cf_udata);
1182 }
1184 return (status);
1185 } /* }}} int plugin_write */
1187 int plugin_flush (const char *plugin, int timeout, const char *identifier)
1188 {
1189 llentry_t *le;
1191 if (list_flush == NULL)
1192 return (0);
1194 le = llist_head (list_flush);
1195 while (le != NULL)
1196 {
1197 callback_func_t *cf;
1198 plugin_flush_cb callback;
1200 if ((plugin != NULL)
1201 && (strcmp (plugin, le->key) != 0))
1202 {
1203 le = le->next;
1204 continue;
1205 }
1207 cf = le->value;
1208 callback = cf->cf_callback;
1210 (*callback) (timeout, identifier, &cf->cf_udata);
1212 le = le->next;
1213 }
1214 return (0);
1215 } /* int plugin_flush */
1217 void plugin_shutdown_all (void)
1218 {
1219 llentry_t *le;
1221 stop_read_threads ();
1223 destroy_all_callbacks (&list_init);
1225 pthread_mutex_lock (&read_lock);
1226 llist_destroy (read_list);
1227 read_list = NULL;
1228 pthread_mutex_unlock (&read_lock);
1230 destroy_read_heap ();
1232 plugin_flush (/* plugin = */ NULL, /* timeout = */ -1,
1233 /* identifier = */ NULL);
1235 le = NULL;
1236 if (list_shutdown != NULL)
1237 le = llist_head (list_shutdown);
1239 while (le != NULL)
1240 {
1241 callback_func_t *cf;
1242 plugin_shutdown_cb callback;
1244 cf = le->value;
1245 callback = cf->cf_callback;
1247 /* Advance the pointer before calling the callback allows
1248 * shutdown functions to unregister themselves. If done the
1249 * other way around the memory `le' points to will be freed
1250 * after callback returns. */
1251 le = le->next;
1253 (*callback) ();
1254 }
1256 /* Write plugins which use the `user_data' pointer usually need the
1257 * same data available to the flush callback. If this is the case, set
1258 * the free_function to NULL when registering the flush callback and to
1259 * the real free function when registering the write callback. This way
1260 * the data isn't freed twice. */
1261 destroy_all_callbacks (&list_flush);
1262 destroy_all_callbacks (&list_write);
1264 destroy_all_callbacks (&list_notification);
1265 destroy_all_callbacks (&list_shutdown);
1266 destroy_all_callbacks (&list_log);
1267 } /* void plugin_shutdown_all */
1269 int plugin_dispatch_values (value_list_t *vl)
1270 {
1271 int status;
1272 static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
1274 value_t *saved_values;
1275 int saved_values_len;
1277 data_set_t *ds;
1279 int free_meta_data = 0;
1281 if ((vl == NULL) || (vl->type[0] == 0)
1282 || (vl->values == NULL) || (vl->values_len < 1))
1283 {
1284 ERROR ("plugin_dispatch_values: Invalid value list.");
1285 return (-1);
1286 }
1288 /* Free meta data only if the calling function didn't specify any. In
1289 * this case matches and targets may add some and the calling function
1290 * may not expect (and therefore free) that data. */
1291 if (vl->meta == NULL)
1292 free_meta_data = 1;
1294 if (list_write == NULL)
1295 c_complain_once (LOG_WARNING, &no_write_complaint,
1296 "plugin_dispatch_values: No write callback has been "
1297 "registered. Please load at least one output plugin, "
1298 "if you want the collected data to be stored.");
1300 if (data_sets == NULL)
1301 {
1302 ERROR ("plugin_dispatch_values: No data sets registered. "
1303 "Could the types database be read? Check "
1304 "your `TypesDB' setting!");
1305 return (-1);
1306 }
1308 if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
1309 {
1310 char ident[6 * DATA_MAX_NAME_LEN];
1312 FORMAT_VL (ident, sizeof (ident), vl);
1313 INFO ("plugin_dispatch_values: Dataset not found: %s "
1314 "(from \"%s\"), check your types.db!",
1315 vl->type, ident);
1316 return (-1);
1317 }
1319 if (vl->time == 0)
1320 vl->time = time (NULL);
1322 if (vl->interval <= 0)
1323 vl->interval = interval_g;
1325 DEBUG ("plugin_dispatch_values: time = %u; interval = %i; "
1326 "host = %s; "
1327 "plugin = %s; plugin_instance = %s; "
1328 "type = %s; type_instance = %s;",
1329 (unsigned int) vl->time, vl->interval,
1330 vl->host,
1331 vl->plugin, vl->plugin_instance,
1332 vl->type, vl->type_instance);
1334 #if COLLECT_DEBUG
1335 assert (0 == strcmp (ds->type, vl->type));
1336 #else
1337 if (0 != strcmp (ds->type, vl->type))
1338 WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
1339 ds->type, vl->type);
1340 #endif
1342 #if COLLECT_DEBUG
1343 assert (ds->ds_num == vl->values_len);
1344 #else
1345 if (ds->ds_num != vl->values_len)
1346 {
1347 ERROR ("plugin_dispatch_values: ds->type = %s: "
1348 "(ds->ds_num = %i) != "
1349 "(vl->values_len = %i)",
1350 ds->type, ds->ds_num, vl->values_len);
1351 return (-1);
1352 }
1353 #endif
1355 escape_slashes (vl->host, sizeof (vl->host));
1356 escape_slashes (vl->plugin, sizeof (vl->plugin));
1357 escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
1358 escape_slashes (vl->type, sizeof (vl->type));
1359 escape_slashes (vl->type_instance, sizeof (vl->type_instance));
1361 /* Copy the values. This way, we can assure `targets' that they get
1362 * dynamically allocated values, which they can free and replace if
1363 * they like. */
1364 if ((pre_cache_chain != NULL) || (post_cache_chain != NULL))
1365 {
1366 saved_values = vl->values;
1367 saved_values_len = vl->values_len;
1369 vl->values = (value_t *) calloc (vl->values_len,
1370 sizeof (*vl->values));
1371 if (vl->values == NULL)
1372 {
1373 ERROR ("plugin_dispatch_values: calloc failed.");
1374 vl->values = saved_values;
1375 return (-1);
1376 }
1377 memcpy (vl->values, saved_values,
1378 vl->values_len * sizeof (*vl->values));
1379 }
1380 else /* if ((pre == NULL) && (post == NULL)) */
1381 {
1382 saved_values = NULL;
1383 saved_values_len = 0;
1384 }
1386 if (pre_cache_chain != NULL)
1387 {
1388 status = fc_process_chain (ds, vl, pre_cache_chain);
1389 if (status < 0)
1390 {
1391 WARNING ("plugin_dispatch_values: Running the "
1392 "pre-cache chain failed with "
1393 "status %i (%#x).",
1394 status, status);
1395 }
1396 else if (status == FC_TARGET_STOP)
1397 {
1398 /* Restore the state of the value_list so that plugins
1399 * don't get confused.. */
1400 if (saved_values != NULL)
1401 {
1402 free (vl->values);
1403 vl->values = saved_values;
1404 vl->values_len = saved_values_len;
1405 }
1406 return (0);
1407 }
1408 }
1410 /* Update the value cache */
1411 uc_update (ds, vl);
1413 /* Initiate threshold checking */
1414 ut_check_threshold (ds, vl);
1416 if (post_cache_chain != NULL)
1417 {
1418 status = fc_process_chain (ds, vl, post_cache_chain);
1419 if (status < 0)
1420 {
1421 WARNING ("plugin_dispatch_values: Running the "
1422 "post-cache chain failed with "
1423 "status %i (%#x).",
1424 status, status);
1425 }
1426 }
1427 else
1428 fc_default_action (ds, vl);
1430 /* Restore the state of the value_list so that plugins don't get
1431 * confused.. */
1432 if (saved_values != NULL)
1433 {
1434 free (vl->values);
1435 vl->values = saved_values;
1436 vl->values_len = saved_values_len;
1437 }
1439 if ((free_meta_data != 0) && (vl->meta != NULL))
1440 {
1441 meta_data_destroy (vl->meta);
1442 vl->meta = NULL;
1443 }
1445 return (0);
1446 } /* int plugin_dispatch_values */
1448 int plugin_dispatch_notification (const notification_t *notif)
1449 {
1450 llentry_t *le;
1451 /* Possible TODO: Add flap detection here */
1453 DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
1454 "time = %u; host = %s;",
1455 notif->severity, notif->message,
1456 (unsigned int) notif->time, notif->host);
1458 /* Nobody cares for notifications */
1459 if (list_notification == NULL)
1460 return (-1);
1462 le = llist_head (list_notification);
1463 while (le != NULL)
1464 {
1465 callback_func_t *cf;
1466 plugin_notification_cb callback;
1467 int status;
1469 cf = le->value;
1470 callback = cf->cf_callback;
1471 status = (*callback) (notif, &cf->cf_udata);
1472 if (status != 0)
1473 {
1474 WARNING ("plugin_dispatch_notification: Notification "
1475 "callback %s returned %i.",
1476 le->key, status);
1477 }
1479 le = le->next;
1480 }
1482 return (0);
1483 } /* int plugin_dispatch_notification */
1485 void plugin_log (int level, const char *format, ...)
1486 {
1487 char msg[1024];
1488 va_list ap;
1489 llentry_t *le;
1491 #if !COLLECT_DEBUG
1492 if (level >= LOG_DEBUG)
1493 return;
1494 #endif
1496 va_start (ap, format);
1497 vsnprintf (msg, sizeof (msg), format, ap);
1498 msg[sizeof (msg) - 1] = '\0';
1499 va_end (ap);
1501 if (list_log == NULL)
1502 {
1503 fprintf (stderr, "%s\n", msg);
1504 return;
1505 }
1507 le = llist_head (list_log);
1508 while (le != NULL)
1509 {
1510 callback_func_t *cf;
1511 plugin_log_cb callback;
1513 cf = le->value;
1514 callback = cf->cf_callback;
1516 (*callback) (level, msg, &cf->cf_udata);
1518 le = le->next;
1519 }
1520 } /* void plugin_log */
1522 const data_set_t *plugin_get_ds (const char *name)
1523 {
1524 data_set_t *ds;
1526 if (c_avl_get (data_sets, name, (void *) &ds) != 0)
1527 {
1528 DEBUG ("No such dataset registered: %s", name);
1529 return (NULL);
1530 }
1532 return (ds);
1533 } /* data_set_t *plugin_get_ds */
1535 static int plugin_notification_meta_add (notification_t *n,
1536 const char *name,
1537 enum notification_meta_type_e type,
1538 const void *value)
1539 {
1540 notification_meta_t *meta;
1541 notification_meta_t *tail;
1543 if ((n == NULL) || (name == NULL) || (value == NULL))
1544 {
1545 ERROR ("plugin_notification_meta_add: A pointer is NULL!");
1546 return (-1);
1547 }
1549 meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
1550 if (meta == NULL)
1551 {
1552 ERROR ("plugin_notification_meta_add: malloc failed.");
1553 return (-1);
1554 }
1555 memset (meta, 0, sizeof (notification_meta_t));
1557 sstrncpy (meta->name, name, sizeof (meta->name));
1558 meta->type = type;
1560 switch (type)
1561 {
1562 case NM_TYPE_STRING:
1563 {
1564 meta->nm_value.nm_string = strdup ((const char *) value);
1565 if (meta->nm_value.nm_string == NULL)
1566 {
1567 ERROR ("plugin_notification_meta_add: strdup failed.");
1568 sfree (meta);
1569 return (-1);
1570 }
1571 break;
1572 }
1573 case NM_TYPE_SIGNED_INT:
1574 {
1575 meta->nm_value.nm_signed_int = *((int64_t *) value);
1576 break;
1577 }
1578 case NM_TYPE_UNSIGNED_INT:
1579 {
1580 meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
1581 break;
1582 }
1583 case NM_TYPE_DOUBLE:
1584 {
1585 meta->nm_value.nm_double = *((double *) value);
1586 break;
1587 }
1588 case NM_TYPE_BOOLEAN:
1589 {
1590 meta->nm_value.nm_boolean = *((bool *) value);
1591 break;
1592 }
1593 default:
1594 {
1595 ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
1596 sfree (meta);
1597 return (-1);
1598 }
1599 } /* switch (type) */
1601 meta->next = NULL;
1602 tail = n->meta;
1603 while ((tail != NULL) && (tail->next != NULL))
1604 tail = tail->next;
1606 if (tail == NULL)
1607 n->meta = meta;
1608 else
1609 tail->next = meta;
1611 return (0);
1612 } /* int plugin_notification_meta_add */
1614 int plugin_notification_meta_add_string (notification_t *n,
1615 const char *name,
1616 const char *value)
1617 {
1618 return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
1619 }
1621 int plugin_notification_meta_add_signed_int (notification_t *n,
1622 const char *name,
1623 int64_t value)
1624 {
1625 return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
1626 }
1628 int plugin_notification_meta_add_unsigned_int (notification_t *n,
1629 const char *name,
1630 uint64_t value)
1631 {
1632 return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
1633 }
1635 int plugin_notification_meta_add_double (notification_t *n,
1636 const char *name,
1637 double value)
1638 {
1639 return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
1640 }
1642 int plugin_notification_meta_add_boolean (notification_t *n,
1643 const char *name,
1644 bool value)
1645 {
1646 return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
1647 }
1649 int plugin_notification_meta_copy (notification_t *dst,
1650 const notification_t *src)
1651 {
1652 notification_meta_t *meta;
1654 assert (dst != NULL);
1655 assert (src != NULL);
1656 assert (dst != src);
1657 assert ((src->meta == NULL) || (src->meta != dst->meta));
1659 for (meta = src->meta; meta != NULL; meta = meta->next)
1660 {
1661 if (meta->type == NM_TYPE_STRING)
1662 plugin_notification_meta_add_string (dst, meta->name,
1663 meta->nm_value.nm_string);
1664 else if (meta->type == NM_TYPE_SIGNED_INT)
1665 plugin_notification_meta_add_signed_int (dst, meta->name,
1666 meta->nm_value.nm_signed_int);
1667 else if (meta->type == NM_TYPE_UNSIGNED_INT)
1668 plugin_notification_meta_add_unsigned_int (dst, meta->name,
1669 meta->nm_value.nm_unsigned_int);
1670 else if (meta->type == NM_TYPE_DOUBLE)
1671 plugin_notification_meta_add_double (dst, meta->name,
1672 meta->nm_value.nm_double);
1673 else if (meta->type == NM_TYPE_BOOLEAN)
1674 plugin_notification_meta_add_boolean (dst, meta->name,
1675 meta->nm_value.nm_boolean);
1676 }
1678 return (0);
1679 } /* int plugin_notification_meta_copy */
1681 int plugin_notification_meta_free (notification_meta_t *n)
1682 {
1683 notification_meta_t *this;
1684 notification_meta_t *next;
1686 if (n == NULL)
1687 {
1688 ERROR ("plugin_notification_meta_free: n == NULL!");
1689 return (-1);
1690 }
1692 this = n;
1693 while (this != NULL)
1694 {
1695 next = this->next;
1697 if (this->type == NM_TYPE_STRING)
1698 {
1699 free ((char *)this->nm_value.nm_string);
1700 this->nm_value.nm_string = NULL;
1701 }
1702 sfree (this);
1704 this = next;
1705 }
1707 return (0);
1708 } /* int plugin_notification_meta_free */
1710 /* vim: set sw=8 ts=8 noet fdm=marker : */