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 (!timeout_reached(rf->rf_next_read) && rc == 0) {
383 rc = pthread_cond_timedwait (&read_cond, &read_lock,
384 &rf->rf_next_read);
385 }
387 /* Must hold `real_lock' when accessing `rf->rf_type'. */
388 rf_type = rf->rf_type;
389 pthread_mutex_unlock (&read_lock);
391 /* Check if we're supposed to stop.. This may have interrupted
392 * the sleep, too. */
393 if (read_loop == 0)
394 {
395 /* Insert `rf' again, so it can be free'd correctly */
396 c_heap_insert (read_heap, rf);
397 break;
398 }
400 /* The entry has been marked for deletion. The linked list
401 * entry has already been removed by `plugin_unregister_read'.
402 * All we have to do here is free the `read_func_t' and
403 * continue. */
404 if (rf_type == RF_REMOVE)
405 {
406 DEBUG ("plugin_read_thread: Destroying the `%s' "
407 "callback.", rf->rf_name);
408 destroy_callback ((callback_func_t *) rf);
409 rf = NULL;
410 continue;
411 }
413 DEBUG ("plugin_read_thread: Handling `%s'.", rf->rf_name);
415 if (rf_type == RF_SIMPLE)
416 {
417 int (*callback) (void);
419 callback = rf->rf_callback;
420 status = (*callback) ();
421 }
422 else
423 {
424 plugin_read_cb callback;
426 assert (rf_type == RF_COMPLEX);
428 callback = rf->rf_callback;
429 status = (*callback) (&rf->rf_udata);
430 }
432 /* If the function signals failure, we will increase the
433 * intervals in which it will be called. */
434 if (status != 0)
435 {
436 rf->rf_effective_interval.tv_sec *= 2;
437 rf->rf_effective_interval.tv_nsec *= 2;
438 NORMALIZE_TIMESPEC (rf->rf_effective_interval);
440 if (rf->rf_effective_interval.tv_sec >= 86400)
441 {
442 rf->rf_effective_interval.tv_sec = 86400;
443 rf->rf_effective_interval.tv_nsec = 0;
444 }
446 NOTICE ("read-function of plugin `%s' failed. "
447 "Will suspend it for %i seconds.",
448 rf->rf_name,
449 (int) rf->rf_effective_interval.tv_sec);
450 }
451 else
452 {
453 /* Success: Restore the interval, if it was changed. */
454 rf->rf_effective_interval = rf->rf_interval;
455 }
457 /* update the ``next read due'' field */
458 gettimeofday (&now, /* timezone = */ NULL);
460 DEBUG ("plugin_read_thread: Effective interval of the "
461 "%s plugin is %i.%09i.",
462 rf->rf_name,
463 (int) rf->rf_effective_interval.tv_sec,
464 (int) rf->rf_effective_interval.tv_nsec);
466 /* Calculate the next (absolute) time at which this function
467 * should be called. */
468 rf->rf_next_read.tv_sec = rf->rf_next_read.tv_sec
469 + rf->rf_effective_interval.tv_sec;
470 rf->rf_next_read.tv_nsec = rf->rf_next_read.tv_nsec
471 + rf->rf_effective_interval.tv_nsec;
472 NORMALIZE_TIMESPEC (rf->rf_next_read);
474 /* Check, if `rf_next_read' is in the past. */
475 if ((rf->rf_next_read.tv_sec < now.tv_sec)
476 || ((rf->rf_next_read.tv_sec == now.tv_sec)
477 && (rf->rf_next_read.tv_nsec < (1000 * now.tv_usec))))
478 {
479 /* `rf_next_read' is in the past. Insert `now'
480 * so this value doesn't trail off into the
481 * past too much. */
482 rf->rf_next_read.tv_sec = now.tv_sec;
483 rf->rf_next_read.tv_nsec = 1000 * now.tv_usec;
484 }
486 DEBUG ("plugin_read_thread: Next read of the %s plugin at %i.%09i.",
487 rf->rf_name,
488 (int) rf->rf_next_read.tv_sec,
489 (int) rf->rf_next_read.tv_nsec);
491 /* Re-insert this read function into the heap again. */
492 c_heap_insert (read_heap, rf);
493 } /* while (read_loop) */
495 pthread_exit (NULL);
496 return ((void *) 0);
497 } /* void *plugin_read_thread */
499 static void start_read_threads (int num)
500 {
501 int i;
503 if (read_threads != NULL)
504 return;
506 read_threads = (pthread_t *) calloc (num, sizeof (pthread_t));
507 if (read_threads == NULL)
508 {
509 ERROR ("plugin: start_read_threads: calloc failed.");
510 return;
511 }
513 read_threads_num = 0;
514 for (i = 0; i < num; i++)
515 {
516 if (pthread_create (read_threads + read_threads_num, NULL,
517 plugin_read_thread, NULL) == 0)
518 {
519 read_threads_num++;
520 }
521 else
522 {
523 ERROR ("plugin: start_read_threads: pthread_create failed.");
524 return;
525 }
526 } /* for (i) */
527 } /* void start_read_threads */
529 static void stop_read_threads (void)
530 {
531 int i;
533 if (read_threads == NULL)
534 return;
536 INFO ("collectd: Stopping %i read threads.", read_threads_num);
538 pthread_mutex_lock (&read_lock);
539 read_loop = 0;
540 DEBUG ("plugin: stop_read_threads: Signalling `read_cond'");
541 pthread_cond_broadcast (&read_cond);
542 pthread_mutex_unlock (&read_lock);
544 for (i = 0; i < read_threads_num; i++)
545 {
546 if (pthread_join (read_threads[i], NULL) != 0)
547 {
548 ERROR ("plugin: stop_read_threads: pthread_join failed.");
549 }
550 read_threads[i] = (pthread_t) 0;
551 }
552 sfree (read_threads);
553 read_threads_num = 0;
554 } /* void stop_read_threads */
556 /*
557 * Public functions
558 */
559 void plugin_set_dir (const char *dir)
560 {
561 if (plugindir != NULL)
562 free (plugindir);
564 if (dir == NULL)
565 plugindir = NULL;
566 else if ((plugindir = strdup (dir)) == NULL)
567 {
568 char errbuf[1024];
569 ERROR ("strdup failed: %s",
570 sstrerror (errno, errbuf, sizeof (errbuf)));
571 }
572 }
574 #define BUFSIZE 512
575 int plugin_load (const char *type, uint32_t flags)
576 {
577 DIR *dh;
578 const char *dir;
579 char filename[BUFSIZE] = "";
580 char typename[BUFSIZE];
581 int typename_len;
582 int ret;
583 struct stat statbuf;
584 struct dirent *de;
585 int status;
587 DEBUG ("type = %s", type);
589 dir = plugin_get_dir ();
590 ret = 1;
592 /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
593 * type when matching the filename */
594 status = ssnprintf (typename, sizeof (typename), "%s.so", type);
595 if ((status < 0) || ((size_t) status >= sizeof (typename)))
596 {
597 WARNING ("snprintf: truncated: `%s.so'", type);
598 return (-1);
599 }
600 typename_len = strlen (typename);
602 if ((dh = opendir (dir)) == NULL)
603 {
604 char errbuf[1024];
605 ERROR ("opendir (%s): %s", dir,
606 sstrerror (errno, errbuf, sizeof (errbuf)));
607 return (-1);
608 }
610 while ((de = readdir (dh)) != NULL)
611 {
612 if (strncasecmp (de->d_name, typename, typename_len))
613 continue;
615 status = ssnprintf (filename, sizeof (filename),
616 "%s/%s", dir, de->d_name);
617 if ((status < 0) || ((size_t) status >= sizeof (filename)))
618 {
619 WARNING ("snprintf: truncated: `%s/%s'", dir, de->d_name);
620 continue;
621 }
623 if (lstat (filename, &statbuf) == -1)
624 {
625 char errbuf[1024];
626 WARNING ("stat %s: %s", filename,
627 sstrerror (errno, errbuf, sizeof (errbuf)));
628 continue;
629 }
630 else if (!S_ISREG (statbuf.st_mode))
631 {
632 /* don't follow symlinks */
633 WARNING ("stat %s: not a regular file", filename);
634 continue;
635 }
637 if (plugin_load_file (filename, flags) == 0)
638 {
639 /* success */
640 ret = 0;
641 break;
642 }
643 else
644 {
645 fprintf (stderr, "Unable to load plugin %s.\n", type);
646 }
647 }
649 closedir (dh);
651 if (filename[0] == '\0')
652 fprintf (stderr, "Could not find plugin %s.\n", type);
654 return (ret);
655 }
657 /*
658 * The `register_*' functions follow
659 */
660 int plugin_register_config (const char *name,
661 int (*callback) (const char *key, const char *val),
662 const char **keys, int keys_num)
663 {
664 cf_register (name, callback, keys, keys_num);
665 return (0);
666 } /* int plugin_register_config */
668 int plugin_register_complex_config (const char *type,
669 int (*callback) (oconfig_item_t *))
670 {
671 return (cf_register_complex (type, callback));
672 } /* int plugin_register_complex_config */
674 int plugin_register_init (const char *name,
675 int (*callback) (void))
676 {
677 return (create_register_callback (&list_init, name, (void *) callback,
678 /* user_data = */ NULL));
679 } /* plugin_register_init */
681 static int plugin_compare_read_func (const void *arg0, const void *arg1)
682 {
683 const read_func_t *rf0;
684 const read_func_t *rf1;
686 rf0 = arg0;
687 rf1 = arg1;
689 if (rf0->rf_next_read.tv_sec < rf1->rf_next_read.tv_sec)
690 return (-1);
691 else if (rf0->rf_next_read.tv_sec > rf1->rf_next_read.tv_sec)
692 return (1);
693 else if (rf0->rf_next_read.tv_nsec < rf1->rf_next_read.tv_nsec)
694 return (-1);
695 else if (rf0->rf_next_read.tv_nsec > rf1->rf_next_read.tv_nsec)
696 return (1);
697 else
698 return (0);
699 } /* int plugin_compare_read_func */
701 /* Add a read function to both, the heap and a linked list. The linked list if
702 * used to look-up read functions, especially for the remove function. The heap
703 * is used to determine which plugin to read next. */
704 static int plugin_insert_read (read_func_t *rf)
705 {
706 int status;
707 llentry_t *le;
709 pthread_mutex_lock (&read_lock);
711 if (read_list == NULL)
712 {
713 read_list = llist_create ();
714 if (read_list == NULL)
715 {
716 pthread_mutex_unlock (&read_lock);
717 ERROR ("plugin_insert_read: read_list failed.");
718 return (-1);
719 }
720 }
722 if (read_heap == NULL)
723 {
724 read_heap = c_heap_create (plugin_compare_read_func);
725 if (read_heap == NULL)
726 {
727 pthread_mutex_unlock (&read_lock);
728 ERROR ("plugin_insert_read: c_heap_create failed.");
729 return (-1);
730 }
731 }
733 le = llentry_create (rf->rf_name, rf);
734 if (le == NULL)
735 {
736 pthread_mutex_unlock (&read_lock);
737 ERROR ("plugin_insert_read: llentry_create failed.");
738 return (-1);
739 }
741 status = c_heap_insert (read_heap, rf);
742 if (status != 0)
743 {
744 pthread_mutex_unlock (&read_lock);
745 ERROR ("plugin_insert_read: c_heap_insert failed.");
746 llentry_destroy (le);
747 return (-1);
748 }
750 /* This does not fail. */
751 llist_append (read_list, le);
753 pthread_mutex_unlock (&read_lock);
754 return (0);
755 } /* int plugin_insert_read */
757 int plugin_register_read (const char *name,
758 int (*callback) (void))
759 {
760 read_func_t *rf;
762 rf = (read_func_t *) malloc (sizeof (read_func_t));
763 if (rf == NULL)
764 {
765 char errbuf[1024];
766 ERROR ("plugin_register_read: malloc failed: %s",
767 sstrerror (errno, errbuf, sizeof (errbuf)));
768 return (-1);
769 }
771 memset (rf, 0, sizeof (read_func_t));
772 rf->rf_callback = (void *) callback;
773 rf->rf_udata.data = NULL;
774 rf->rf_udata.free_func = NULL;
775 sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
776 rf->rf_type = RF_SIMPLE;
777 rf->rf_interval.tv_sec = 0;
778 rf->rf_interval.tv_nsec = 0;
779 rf->rf_effective_interval = rf->rf_interval;
781 return (plugin_insert_read (rf));
782 } /* int plugin_register_read */
784 int plugin_register_complex_read (const char *name,
785 plugin_read_cb callback,
786 const struct timespec *interval,
787 user_data_t *user_data)
788 {
789 read_func_t *rf;
791 rf = (read_func_t *) malloc (sizeof (read_func_t));
792 if (rf == NULL)
793 {
794 ERROR ("plugin_register_complex_read: malloc failed.");
795 return (-1);
796 }
798 memset (rf, 0, sizeof (read_func_t));
799 rf->rf_callback = (void *) callback;
800 sstrncpy (rf->rf_name, name, sizeof (rf->rf_name));
801 rf->rf_type = RF_COMPLEX;
802 if (interval != NULL)
803 {
804 rf->rf_interval = *interval;
805 }
806 rf->rf_effective_interval = rf->rf_interval;
808 /* Set user data */
809 if (user_data == NULL)
810 {
811 rf->rf_udata.data = NULL;
812 rf->rf_udata.free_func = NULL;
813 }
814 else
815 {
816 rf->rf_udata = *user_data;
817 }
819 return (plugin_insert_read (rf));
820 } /* int plugin_register_complex_read */
822 int plugin_register_write (const char *name,
823 plugin_write_cb callback, user_data_t *ud)
824 {
825 return (create_register_callback (&list_write, name,
826 (void *) callback, ud));
827 } /* int plugin_register_write */
829 int plugin_register_flush (const char *name,
830 plugin_flush_cb callback, user_data_t *ud)
831 {
832 return (create_register_callback (&list_flush, name,
833 (void *) callback, ud));
834 } /* int plugin_register_flush */
836 int plugin_register_shutdown (char *name,
837 int (*callback) (void))
838 {
839 return (create_register_callback (&list_shutdown, name,
840 (void *) callback, /* user_data = */ NULL));
841 } /* int plugin_register_shutdown */
843 int plugin_register_data_set (const data_set_t *ds)
844 {
845 data_set_t *ds_copy;
846 int i;
848 if ((data_sets != NULL)
849 && (c_avl_get (data_sets, ds->type, NULL) == 0))
850 {
851 NOTICE ("Replacing DS `%s' with another version.", ds->type);
852 plugin_unregister_data_set (ds->type);
853 }
854 else if (data_sets == NULL)
855 {
856 data_sets = c_avl_create ((int (*) (const void *, const void *)) strcmp);
857 if (data_sets == NULL)
858 return (-1);
859 }
861 ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
862 if (ds_copy == NULL)
863 return (-1);
864 memcpy(ds_copy, ds, sizeof (data_set_t));
866 ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
867 * ds->ds_num);
868 if (ds_copy->ds == NULL)
869 {
870 free (ds_copy);
871 return (-1);
872 }
874 for (i = 0; i < ds->ds_num; i++)
875 memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
877 return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
878 } /* int plugin_register_data_set */
880 int plugin_register_log (const char *name,
881 plugin_log_cb callback, user_data_t *ud)
882 {
883 return (create_register_callback (&list_log, name,
884 (void *) callback, ud));
885 } /* int plugin_register_log */
887 int plugin_register_notification (const char *name,
888 plugin_notification_cb callback, user_data_t *ud)
889 {
890 return (create_register_callback (&list_notification, name,
891 (void *) callback, ud));
892 } /* int plugin_register_log */
894 int plugin_unregister_config (const char *name)
895 {
896 cf_unregister (name);
897 return (0);
898 } /* int plugin_unregister_config */
900 int plugin_unregister_complex_config (const char *name)
901 {
902 cf_unregister_complex (name);
903 return (0);
904 } /* int plugin_unregister_complex_config */
906 int plugin_unregister_init (const char *name)
907 {
908 return (plugin_unregister (list_init, name));
909 }
911 int plugin_unregister_read (const char *name) /* {{{ */
912 {
913 llentry_t *le;
914 read_func_t *rf;
916 if (name == NULL)
917 return (-ENOENT);
919 pthread_mutex_lock (&read_lock);
921 if (read_list == NULL)
922 {
923 pthread_mutex_unlock (&read_lock);
924 return (-ENOENT);
925 }
927 le = llist_search (read_list, name);
928 if (le == NULL)
929 {
930 pthread_mutex_unlock (&read_lock);
931 WARNING ("plugin_unregister_read: No such read function: %s",
932 name);
933 return (-ENOENT);
934 }
936 llist_remove (read_list, le);
938 rf = le->value;
939 assert (rf != NULL);
940 rf->rf_type = RF_REMOVE;
942 pthread_mutex_unlock (&read_lock);
944 llentry_destroy (le);
946 DEBUG ("plugin_unregister_read: Marked `%s' for removal.", name);
948 return (0);
949 } /* }}} int plugin_unregister_read */
951 int plugin_unregister_write (const char *name)
952 {
953 return (plugin_unregister (list_write, name));
954 }
956 int plugin_unregister_flush (const char *name)
957 {
958 return (plugin_unregister (list_flush, name));
959 }
961 int plugin_unregister_shutdown (const char *name)
962 {
963 return (plugin_unregister (list_shutdown, name));
964 }
966 int plugin_unregister_data_set (const char *name)
967 {
968 data_set_t *ds;
970 if (data_sets == NULL)
971 return (-1);
973 if (c_avl_remove (data_sets, name, NULL, (void *) &ds) != 0)
974 return (-1);
976 sfree (ds->ds);
977 sfree (ds);
979 return (0);
980 } /* int plugin_unregister_data_set */
982 int plugin_unregister_log (const char *name)
983 {
984 return (plugin_unregister (list_log, name));
985 }
987 int plugin_unregister_notification (const char *name)
988 {
989 return (plugin_unregister (list_notification, name));
990 }
992 void plugin_init_all (void)
993 {
994 const char *chain_name;
995 llentry_t *le;
996 int status;
998 /* Init the value cache */
999 uc_init ();
1001 chain_name = global_option_get ("PreCacheChain");
1002 pre_cache_chain = fc_chain_get_by_name (chain_name);
1004 chain_name = global_option_get ("PostCacheChain");
1005 post_cache_chain = fc_chain_get_by_name (chain_name);
1008 if ((list_init == NULL) && (read_heap == NULL))
1009 return;
1011 /* Calling all init callbacks before checking if read callbacks
1012 * are available allows the init callbacks to register the read
1013 * callback. */
1014 le = llist_head (list_init);
1015 while (le != NULL)
1016 {
1017 callback_func_t *cf;
1018 plugin_init_cb callback;
1020 cf = le->value;
1021 callback = cf->cf_callback;
1022 status = (*callback) ();
1024 if (status != 0)
1025 {
1026 ERROR ("Initialization of plugin `%s' "
1027 "failed with status %i. "
1028 "Plugin will be unloaded.",
1029 le->key, status);
1030 /* Plugins that register read callbacks from the init
1031 * callback should take care of appropriate error
1032 * handling themselves. */
1033 /* FIXME: Unload _all_ functions */
1034 plugin_unregister_read (le->key);
1035 }
1037 le = le->next;
1038 }
1040 /* Start read-threads */
1041 if (read_heap != NULL)
1042 {
1043 const char *rt;
1044 int num;
1045 rt = global_option_get ("ReadThreads");
1046 num = atoi (rt);
1047 if (num != -1)
1048 start_read_threads ((num > 0) ? num : 5);
1049 }
1050 } /* void plugin_init_all */
1052 /* TODO: Rename this function. */
1053 void plugin_read_all (void)
1054 {
1055 uc_check_timeout ();
1057 return;
1058 } /* void plugin_read_all */
1060 /* Read function called when the `-T' command line argument is given. */
1061 int plugin_read_all_once (void)
1062 {
1063 int status;
1064 int return_status = 0;
1066 if (read_heap == NULL)
1067 {
1068 NOTICE ("No read-functions are registered.");
1069 return (0);
1070 }
1072 while (42)
1073 {
1074 read_func_t *rf;
1076 rf = c_heap_get_root (read_heap);
1077 if (rf == NULL)
1078 break;
1080 if (rf->rf_type == RF_SIMPLE)
1081 {
1082 int (*callback) (void);
1084 callback = rf->rf_callback;
1085 status = (*callback) ();
1086 }
1087 else
1088 {
1089 plugin_read_cb callback;
1091 callback = rf->rf_callback;
1092 status = (*callback) (&rf->rf_udata);
1093 }
1095 if (status != 0)
1096 {
1097 NOTICE ("read-function of plugin `%s' failed.",
1098 rf->rf_name);
1099 return_status = -1;
1100 }
1102 destroy_callback ((void *) rf);
1103 }
1105 return (return_status);
1106 } /* int plugin_read_all_once */
1108 int plugin_write (const char *plugin, /* {{{ */
1109 const data_set_t *ds, const value_list_t *vl)
1110 {
1111 llentry_t *le;
1112 int status;
1114 if (vl == NULL)
1115 return (EINVAL);
1117 if (list_write == NULL)
1118 return (ENOENT);
1120 if (ds == NULL)
1121 {
1122 ds = plugin_get_ds (vl->type);
1123 if (ds == NULL)
1124 {
1125 ERROR ("plugin_write: Unable to lookup type `%s'.", vl->type);
1126 return (ENOENT);
1127 }
1128 }
1130 if (plugin == NULL)
1131 {
1132 int success = 0;
1133 int failure = 0;
1135 le = llist_head (list_write);
1136 while (le != NULL)
1137 {
1138 callback_func_t *cf = le->value;
1139 plugin_write_cb callback;
1141 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
1142 callback = cf->cf_callback;
1143 status = (*callback) (ds, vl, &cf->cf_udata);
1144 if (status != 0)
1145 failure++;
1146 else
1147 success++;
1149 le = le->next;
1150 }
1152 if ((success == 0) && (failure != 0))
1153 status = -1;
1154 else
1155 status = 0;
1156 }
1157 else /* plugin != NULL */
1158 {
1159 callback_func_t *cf;
1160 plugin_write_cb callback;
1162 le = llist_head (list_write);
1163 while (le != NULL)
1164 {
1165 if (strcasecmp (plugin, le->key) == 0)
1166 break;
1168 le = le->next;
1169 }
1171 if (le == NULL)
1172 return (ENOENT);
1174 cf = le->value;
1176 DEBUG ("plugin: plugin_write: Writing values via %s.", le->key);
1177 callback = cf->cf_callback;
1178 status = (*callback) (ds, vl, &cf->cf_udata);
1179 }
1181 return (status);
1182 } /* }}} int plugin_write */
1184 int plugin_flush (const char *plugin, int timeout, const char *identifier)
1185 {
1186 llentry_t *le;
1188 if (list_flush == NULL)
1189 return (0);
1191 le = llist_head (list_flush);
1192 while (le != NULL)
1193 {
1194 callback_func_t *cf;
1195 plugin_flush_cb callback;
1197 if ((plugin != NULL)
1198 && (strcmp (plugin, le->key) != 0))
1199 {
1200 le = le->next;
1201 continue;
1202 }
1204 cf = le->value;
1205 callback = cf->cf_callback;
1207 (*callback) (timeout, identifier, &cf->cf_udata);
1209 le = le->next;
1210 }
1211 return (0);
1212 } /* int plugin_flush */
1214 void plugin_shutdown_all (void)
1215 {
1216 llentry_t *le;
1218 stop_read_threads ();
1220 destroy_all_callbacks (&list_init);
1222 pthread_mutex_lock (&read_lock);
1223 llist_destroy (read_list);
1224 read_list = NULL;
1225 pthread_mutex_unlock (&read_lock);
1227 destroy_read_heap ();
1229 plugin_flush (/* plugin = */ NULL, /* timeout = */ -1,
1230 /* identifier = */ NULL);
1232 le = NULL;
1233 if (list_shutdown != NULL)
1234 le = llist_head (list_shutdown);
1236 while (le != NULL)
1237 {
1238 callback_func_t *cf;
1239 plugin_shutdown_cb callback;
1241 cf = le->value;
1242 callback = cf->cf_callback;
1244 /* Advance the pointer before calling the callback allows
1245 * shutdown functions to unregister themselves. If done the
1246 * other way around the memory `le' points to will be freed
1247 * after callback returns. */
1248 le = le->next;
1250 (*callback) ();
1251 }
1253 /* Write plugins which use the `user_data' pointer usually need the
1254 * same data available to the flush callback. If this is the case, set
1255 * the free_function to NULL when registering the flush callback and to
1256 * the real free function when registering the write callback. This way
1257 * the data isn't freed twice. */
1258 destroy_all_callbacks (&list_flush);
1259 destroy_all_callbacks (&list_write);
1261 destroy_all_callbacks (&list_notification);
1262 destroy_all_callbacks (&list_shutdown);
1263 destroy_all_callbacks (&list_log);
1264 } /* void plugin_shutdown_all */
1266 int plugin_dispatch_values (value_list_t *vl)
1267 {
1268 int status;
1269 static c_complain_t no_write_complaint = C_COMPLAIN_INIT_STATIC;
1271 value_t *saved_values;
1272 int saved_values_len;
1274 data_set_t *ds;
1276 int free_meta_data = 0;
1278 if ((vl == NULL) || (vl->type[0] == 0)
1279 || (vl->values == NULL) || (vl->values_len < 1))
1280 {
1281 ERROR ("plugin_dispatch_values: Invalid value list.");
1282 return (-1);
1283 }
1285 /* Free meta data only if the calling function didn't specify any. In
1286 * this case matches and targets may add some and the calling function
1287 * may not expect (and therefore free) that data. */
1288 if (vl->meta == NULL)
1289 free_meta_data = 1;
1291 if (list_write == NULL)
1292 c_complain_once (LOG_WARNING, &no_write_complaint,
1293 "plugin_dispatch_values: No write callback has been "
1294 "registered. Please load at least one output plugin, "
1295 "if you want the collected data to be stored.");
1297 if (data_sets == NULL)
1298 {
1299 ERROR ("plugin_dispatch_values: No data sets registered. "
1300 "Could the types database be read? Check "
1301 "your `TypesDB' setting!");
1302 return (-1);
1303 }
1305 if (c_avl_get (data_sets, vl->type, (void *) &ds) != 0)
1306 {
1307 INFO ("plugin_dispatch_values: Dataset not found: %s", vl->type);
1308 return (-1);
1309 }
1311 if (vl->time == 0)
1312 vl->time = time (NULL);
1314 if (vl->interval <= 0)
1315 vl->interval = interval_g;
1317 DEBUG ("plugin_dispatch_values: time = %u; interval = %i; "
1318 "host = %s; "
1319 "plugin = %s; plugin_instance = %s; "
1320 "type = %s; type_instance = %s;",
1321 (unsigned int) vl->time, vl->interval,
1322 vl->host,
1323 vl->plugin, vl->plugin_instance,
1324 vl->type, vl->type_instance);
1326 #if COLLECT_DEBUG
1327 assert (0 == strcmp (ds->type, vl->type));
1328 #else
1329 if (0 != strcmp (ds->type, vl->type))
1330 WARNING ("plugin_dispatch_values: (ds->type = %s) != (vl->type = %s)",
1331 ds->type, vl->type);
1332 #endif
1334 #if COLLECT_DEBUG
1335 assert (ds->ds_num == vl->values_len);
1336 #else
1337 if (ds->ds_num != vl->values_len)
1338 {
1339 ERROR ("plugin_dispatch_values: ds->type = %s: "
1340 "(ds->ds_num = %i) != "
1341 "(vl->values_len = %i)",
1342 ds->type, ds->ds_num, vl->values_len);
1343 return (-1);
1344 }
1345 #endif
1347 escape_slashes (vl->host, sizeof (vl->host));
1348 escape_slashes (vl->plugin, sizeof (vl->plugin));
1349 escape_slashes (vl->plugin_instance, sizeof (vl->plugin_instance));
1350 escape_slashes (vl->type, sizeof (vl->type));
1351 escape_slashes (vl->type_instance, sizeof (vl->type_instance));
1353 /* Copy the values. This way, we can assure `targets' that they get
1354 * dynamically allocated values, which they can free and replace if
1355 * they like. */
1356 if ((pre_cache_chain != NULL) || (post_cache_chain != NULL))
1357 {
1358 saved_values = vl->values;
1359 saved_values_len = vl->values_len;
1361 vl->values = (value_t *) calloc (vl->values_len,
1362 sizeof (*vl->values));
1363 if (vl->values == NULL)
1364 {
1365 ERROR ("plugin_dispatch_values: calloc failed.");
1366 vl->values = saved_values;
1367 return (-1);
1368 }
1369 memcpy (vl->values, saved_values,
1370 vl->values_len * sizeof (*vl->values));
1371 }
1372 else /* if ((pre == NULL) && (post == NULL)) */
1373 {
1374 saved_values = NULL;
1375 saved_values_len = 0;
1376 }
1378 if (pre_cache_chain != NULL)
1379 {
1380 status = fc_process_chain (ds, vl, pre_cache_chain);
1381 if (status < 0)
1382 {
1383 WARNING ("plugin_dispatch_values: Running the "
1384 "pre-cache chain failed with "
1385 "status %i (%#x).",
1386 status, status);
1387 }
1388 else if (status == FC_TARGET_STOP)
1389 {
1390 /* Restore the state of the value_list so that plugins
1391 * don't get confused.. */
1392 if (saved_values != NULL)
1393 {
1394 free (vl->values);
1395 vl->values = saved_values;
1396 vl->values_len = saved_values_len;
1397 }
1398 return (0);
1399 }
1400 }
1402 /* Update the value cache */
1403 uc_update (ds, vl);
1405 /* Initiate threshold checking */
1406 ut_check_threshold (ds, vl);
1408 if (post_cache_chain != NULL)
1409 {
1410 status = fc_process_chain (ds, vl, post_cache_chain);
1411 if (status < 0)
1412 {
1413 WARNING ("plugin_dispatch_values: Running the "
1414 "post-cache chain failed with "
1415 "status %i (%#x).",
1416 status, status);
1417 }
1418 }
1419 else
1420 fc_default_action (ds, vl);
1422 /* Restore the state of the value_list so that plugins don't get
1423 * confused.. */
1424 if (saved_values != NULL)
1425 {
1426 free (vl->values);
1427 vl->values = saved_values;
1428 vl->values_len = saved_values_len;
1429 }
1431 if ((free_meta_data != 0) && (vl->meta != NULL))
1432 {
1433 meta_data_destroy (vl->meta);
1434 vl->meta = NULL;
1435 }
1437 return (0);
1438 } /* int plugin_dispatch_values */
1440 int plugin_dispatch_notification (const notification_t *notif)
1441 {
1442 llentry_t *le;
1443 /* Possible TODO: Add flap detection here */
1445 DEBUG ("plugin_dispatch_notification: severity = %i; message = %s; "
1446 "time = %u; host = %s;",
1447 notif->severity, notif->message,
1448 (unsigned int) notif->time, notif->host);
1450 /* Nobody cares for notifications */
1451 if (list_notification == NULL)
1452 return (-1);
1454 le = llist_head (list_notification);
1455 while (le != NULL)
1456 {
1457 callback_func_t *cf;
1458 plugin_notification_cb callback;
1459 int status;
1461 cf = le->value;
1462 callback = cf->cf_callback;
1463 status = (*callback) (notif, &cf->cf_udata);
1464 if (status != 0)
1465 {
1466 WARNING ("plugin_dispatch_notification: Notification "
1467 "callback %s returned %i.",
1468 le->key, status);
1469 }
1471 le = le->next;
1472 }
1474 return (0);
1475 } /* int plugin_dispatch_notification */
1477 void plugin_log (int level, const char *format, ...)
1478 {
1479 char msg[1024];
1480 va_list ap;
1481 llentry_t *le;
1483 if (list_log == NULL)
1484 {
1485 va_start (ap, format);
1486 vfprintf (stderr, format, ap);
1487 va_end (ap);
1488 return;
1489 }
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 le = llist_head (list_log);
1502 while (le != NULL)
1503 {
1504 callback_func_t *cf;
1505 plugin_log_cb callback;
1507 cf = le->value;
1508 callback = cf->cf_callback;
1510 (*callback) (level, msg, &cf->cf_udata);
1512 le = le->next;
1513 }
1514 } /* void plugin_log */
1516 const data_set_t *plugin_get_ds (const char *name)
1517 {
1518 data_set_t *ds;
1520 if (c_avl_get (data_sets, name, (void *) &ds) != 0)
1521 {
1522 DEBUG ("No such dataset registered: %s", name);
1523 return (NULL);
1524 }
1526 return (ds);
1527 } /* data_set_t *plugin_get_ds */
1529 static int plugin_notification_meta_add (notification_t *n,
1530 const char *name,
1531 enum notification_meta_type_e type,
1532 const void *value)
1533 {
1534 notification_meta_t *meta;
1535 notification_meta_t *tail;
1537 if ((n == NULL) || (name == NULL) || (value == NULL))
1538 {
1539 ERROR ("plugin_notification_meta_add: A pointer is NULL!");
1540 return (-1);
1541 }
1543 meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
1544 if (meta == NULL)
1545 {
1546 ERROR ("plugin_notification_meta_add: malloc failed.");
1547 return (-1);
1548 }
1549 memset (meta, 0, sizeof (notification_meta_t));
1551 sstrncpy (meta->name, name, sizeof (meta->name));
1552 meta->type = type;
1554 switch (type)
1555 {
1556 case NM_TYPE_STRING:
1557 {
1558 meta->nm_value.nm_string = strdup ((const char *) value);
1559 if (meta->nm_value.nm_string == NULL)
1560 {
1561 ERROR ("plugin_notification_meta_add: strdup failed.");
1562 sfree (meta);
1563 return (-1);
1564 }
1565 break;
1566 }
1567 case NM_TYPE_SIGNED_INT:
1568 {
1569 meta->nm_value.nm_signed_int = *((int64_t *) value);
1570 break;
1571 }
1572 case NM_TYPE_UNSIGNED_INT:
1573 {
1574 meta->nm_value.nm_unsigned_int = *((uint64_t *) value);
1575 break;
1576 }
1577 case NM_TYPE_DOUBLE:
1578 {
1579 meta->nm_value.nm_double = *((double *) value);
1580 break;
1581 }
1582 case NM_TYPE_BOOLEAN:
1583 {
1584 meta->nm_value.nm_boolean = *((bool *) value);
1585 break;
1586 }
1587 default:
1588 {
1589 ERROR ("plugin_notification_meta_add: Unknown type: %i", type);
1590 sfree (meta);
1591 return (-1);
1592 }
1593 } /* switch (type) */
1595 meta->next = NULL;
1596 tail = n->meta;
1597 while ((tail != NULL) && (tail->next != NULL))
1598 tail = tail->next;
1600 if (tail == NULL)
1601 n->meta = meta;
1602 else
1603 tail->next = meta;
1605 return (0);
1606 } /* int plugin_notification_meta_add */
1608 int plugin_notification_meta_add_string (notification_t *n,
1609 const char *name,
1610 const char *value)
1611 {
1612 return (plugin_notification_meta_add (n, name, NM_TYPE_STRING, value));
1613 }
1615 int plugin_notification_meta_add_signed_int (notification_t *n,
1616 const char *name,
1617 int64_t value)
1618 {
1619 return (plugin_notification_meta_add (n, name, NM_TYPE_SIGNED_INT, &value));
1620 }
1622 int plugin_notification_meta_add_unsigned_int (notification_t *n,
1623 const char *name,
1624 uint64_t value)
1625 {
1626 return (plugin_notification_meta_add (n, name, NM_TYPE_UNSIGNED_INT, &value));
1627 }
1629 int plugin_notification_meta_add_double (notification_t *n,
1630 const char *name,
1631 double value)
1632 {
1633 return (plugin_notification_meta_add (n, name, NM_TYPE_DOUBLE, &value));
1634 }
1636 int plugin_notification_meta_add_boolean (notification_t *n,
1637 const char *name,
1638 bool value)
1639 {
1640 return (plugin_notification_meta_add (n, name, NM_TYPE_BOOLEAN, &value));
1641 }
1643 int plugin_notification_meta_copy (notification_t *dst,
1644 const notification_t *src)
1645 {
1646 notification_meta_t *meta;
1648 assert (dst != NULL);
1649 assert (src != NULL);
1650 assert (dst != src);
1651 assert ((src->meta == NULL) || (src->meta != dst->meta));
1653 for (meta = src->meta; meta != NULL; meta = meta->next)
1654 {
1655 if (meta->type == NM_TYPE_STRING)
1656 plugin_notification_meta_add_string (dst, meta->name,
1657 meta->nm_value.nm_string);
1658 else if (meta->type == NM_TYPE_SIGNED_INT)
1659 plugin_notification_meta_add_signed_int (dst, meta->name,
1660 meta->nm_value.nm_signed_int);
1661 else if (meta->type == NM_TYPE_UNSIGNED_INT)
1662 plugin_notification_meta_add_unsigned_int (dst, meta->name,
1663 meta->nm_value.nm_unsigned_int);
1664 else if (meta->type == NM_TYPE_DOUBLE)
1665 plugin_notification_meta_add_double (dst, meta->name,
1666 meta->nm_value.nm_double);
1667 else if (meta->type == NM_TYPE_BOOLEAN)
1668 plugin_notification_meta_add_boolean (dst, meta->name,
1669 meta->nm_value.nm_boolean);
1670 }
1672 return (0);
1673 } /* int plugin_notification_meta_copy */
1675 int plugin_notification_meta_free (notification_meta_t *n)
1676 {
1677 notification_meta_t *this;
1678 notification_meta_t *next;
1680 if (n == NULL)
1681 {
1682 ERROR ("plugin_notification_meta_free: n == NULL!");
1683 return (-1);
1684 }
1686 this = n;
1687 while (this != NULL)
1688 {
1689 next = this->next;
1691 if (this->type == NM_TYPE_STRING)
1692 {
1693 free ((char *)this->nm_value.nm_string);
1694 this->nm_value.nm_string = NULL;
1695 }
1696 sfree (this);
1698 this = next;
1699 }
1701 return (0);
1702 } /* int plugin_notification_meta_free */
1704 /* vim: set sw=8 ts=8 noet fdm=marker : */