summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8f7201d)
raw | patch | inline | side by side (parent: 8f7201d)
author | octo <octo> | |
Mon, 12 Dec 2005 08:06:53 +0000 (08:06 +0000) | ||
committer | octo <octo> | |
Mon, 12 Dec 2005 08:06:53 +0000 (08:06 +0000) |
AUTHORS | patch | blob | history | |
Makefile.am | patch | blob | history | |
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/plugin.c | [new file with mode: 0644] | patch | blob |
index 020261a28ba61fa2369f1c9e5e6a8f4ed1a09b7b..52b63075d297da91c23b20ac4ec09ab52e60bc99 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
don't-fork-patch by:
Alvaro Barcellos <alvaro.barcellos@gmail.com>
+many autotools related fixes, libltdl code, getmnt-wizardry and much help has
+contributed:
+ Niki W. Waibel <niki.waibel@newlogic.com>
+
collectd is available at:
<http://verplant.org/collectd/>
diff --git a/Makefile.am b/Makefile.am
index 39b12b1f77bc461ee477cbe8c9790a7d0a25def5..c60110c4c22c014ff92742f9fa053b9ccfab1877 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
-AUTOMAKE_OPTIONS = dist-bzip2
-
-SUBDIRS = src
+SUBDIRS = libltdl src
+INCLUDES = $(LTDLINCL)
EXTRA_DIST = collectd.spec contrib debian
diff --git a/configure.in b/configure.in
index 889706e4b8bff74e968b3e97c3cd688608a43614..4d8023e6a8d7ffcc1dc7d7c24a05d64f6bf81010 100644 (file)
--- a/configure.in
+++ b/configure.in
dnl Process this file with autoconf to produce a configure script.
-AC_INIT(src/collectd.c)
-AM_INIT_AUTOMAKE(collectd, 3.5.alpha1)
-AM_CONFIG_HEADER(src/config.h src/libping/config.h)
+AC_INIT(collectd, 3.5.alpha1-quota)
+AC_CONFIG_SRCDIR(src/collectd.c)
+AC_CONFIG_HEADERS(src/config.h)
+AM_INIT_AUTOMAKE(dist-bzip2)
AC_LANG(C)
AC_PREFIX_DEFAULT("/opt/collectd")
dnl configure libtool
AC_DISABLE_STATIC
+AC_LIBLTDL_CONVENIENCE
+AC_SUBST(LTDLINCL)
+AC_SUBST(LIBLTDL)
AC_LIBTOOL_DLOPEN
AC_PROG_LIBTOOL
#AC_PROG_RANLIB
+AC_CONFIG_SUBDIRS(libltdl)
#
# Checks for header files.
#
-AC_HEADER_STDC
AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS(fcntl.h unistd.h)
+AC_HEADER_DIRENT
+AC_CHECK_HEADERS(fcntl.h)
AC_CHECK_HEADERS(signal.h)
AC_CHECK_HEADERS(sys/socket.h)
AC_CHECK_HEADERS(sys/select.h)
AC_CHECK_HEADERS(netdb.h)
-AC_CHECK_HEADERS(sys/time.h sys/times.h)
-AC_CHECK_HEADERS(sys/types.h)
AC_CHECK_HEADERS(sys/resource.h)
AC_CHECK_HEADERS(errno.h)
AC_CHECK_HEADERS(syslog.h)
-AC_CHECK_HEADERS(dlfcn.h)
# For cpu modules
AC_CHECK_HEADERS(sys/sysctl.h sys/dkstat.h)
# For ping module
AC_CHECK_HEADERS(arpa/inet.h)
AC_CHECK_HEADERS(netinet/in.h)
-AC_CHECK_HEADERS(netdb.h)
# For users module
AC_CHECK_HEADERS(utmp.h)
AC_CHECK_HEADERS(utmpx.h)
+# For quota module
+AC_CHECK_HEADERS(grp.h pwd.h sys/ucred.h)
+AC_CHECK_HEADERS(ctype.h)
+AC_CHECK_HEADERS(limits.h)
+AC_CHECK_HEADERS(sys/quota.h)
+AC_CHECK_HEADERS(xfs/xqm.h)
+
+# For mount interface
+AC_CHECK_HEADERS(fs_info.h)
+AC_CHECK_HEADERS(fshelp.h)
+AC_CHECK_HEADERS(paths.h)
+AC_CHECK_HEADERS(mntent.h)
+AC_CHECK_HEADERS(mnttab.h)
+AC_CHECK_HEADERS(sys/fstyp.h)
+AC_CHECK_HEADERS(sys/fs_types.h)
+AC_CHECK_HEADERS(sys/mntent.h)
+AC_CHECK_HEADERS(sys/mnttab.h)
+AC_CHECK_HEADERS(sys/mount.h)
+AC_CHECK_HEADERS(sys/statfs.h)
+AC_CHECK_HEADERS(sys/vfs.h)
+AC_CHECK_HEADERS(sys/vfstab.h)
+
+# For debugging interface (variable number of arguments)
+AC_CHECK_HEADERS(stdarg.h)
+
dnl Checking for libraries
AC_CHECK_LIB(m, ext)
# Checks for library functions.
#
AC_PROG_GCC_TRADITIONAL
-AC_CHECK_FUNCS(gettimeofday select socket strdup strstr strtol)
+AC_CHECK_FUNCS(gettimeofday select strdup strtol)
AC_CHECK_FUNCS(socket, , AC_CHECK_LIB(socket, socket))
AC_CHECK_FUNCS(gethostbyname, , AC_CHECK_LIB(nsl, gethostbyname))
AC_CHECK_FUNCS(strchr memcpy strstr strcmp strncmp strncpy strlen)
-AC_CHECK_FUNCS(strncasecmp strcasecmp strncmp)
+AC_CHECK_FUNCS(strncasecmp strcasecmp)
# For cpu module
AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
have_getutent="no"
AC_CHECK_FUNCS(getutent getutxent, [have_getutent="yes"])
+# For quota module
+AC_CHECK_FUNCS(quotactl)
+AC_CHECK_FUNCS(getgrgid getpwuid)
+
+# For mount interface
+AC_CHECK_FUNCS(getfsent getvfsent listmntent)
+AC_FUNC_GETMNTENT
+if test "x$ac_cv_func_getmntent" = 'xyes'; then
+ saveCFLAGS="$CFLAGS"
+ CFLAGS="-Wall -Werror $CFLAGS"
+ AC_CACHE_CHECK([whether getmntent takes one argument],
+ [fu_cv_getmntent1],
+ AC_COMPILE_IFELSE(
+ AC_LANG_PROGRAM([[AC_INCLUDES_DEFAULT
+#include "$srcdir/src/utils_mount.h"]],
+ [[(void)getmntent((FILE *)NULL);]]
+ ),
+ [fu_cv_getmntent1=yes],
+ [fu_cv_getmntent1=no]
+ )
+ )
+ if test "x$fu_cv_getmntent1" = 'xno'; then
+ AC_CACHE_CHECK([whether getmntent takes two arguments],
+ [fu_cv_getmntent2],
+ AC_COMPILE_IFELSE(
+ AC_LANG_PROGRAM([[AC_INCLUDES_DEFAULT
+#include "$srcdir/src/utils_mount.h"]],
+ [[(void)getmntent((FILE *)NULL,
+ (struct mnttab *)NULL);]]
+ ),
+ [fu_cv_getmntent2=yes],
+ [fu_cv_getmntent2=no]
+ )
+ )
+ fi
+ CFLAGS="$saveCFLAGS"
+fi
+if test "x$fu_cv_getmntent1" = 'xyes'; then
+ AC_DEFINE(HAVE_GETMNTENT1,
+ 1,
+ [Define if there is a function named getmntent
+ for reading the list of mounted filesystems, and
+ that function takes a single argument. (4.3BSD,
+ SunOS, HP-UX, Dynix, Irix, Linux)]
+ )
+fi
+if test "x$fu_cv_getmntent2" = 'xyes'; then
+ AC_DEFINE(HAVE_GETMNTENT2,
+ 1,
+ [Define if there is a function named getmntent
+ for reading the list of mounted filesystems, and
+ that function takes two arguments. (SVR4)]
+ )
+fi
+
AC_MSG_CHECKING([for kernel type ($host_os)])
case $host_os in
*linux*)
dnl Checks for libraries.
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(resolv, res_search)
-AC_CHECK_LIB(dl, dlopen)
# AC_ARG_WITH (package, help-string, [action-if-given], [action-if-not-given])
AC_ARG_WITH(rrdtool, AC_HELP_STRING([--with-rrdtool=PFX], [Path to rrdtool.]),
fi
AM_CONDITIONAL(BUILD_WITH_RRDTOOL, test "x$with_rrdtool" = "xyes")
+#AC_ARG_WITH(pth, AC_HELP_STRING([--with-pth=PFX], [Path to pth (experimental).]),
+#[ if test "x$withval" != "xno" -a "x$withval" != "xyes"
+# then
+# LDFLAGS="$LDFLAGS -L$withval/lib"
+# CPPFLAGS="$CPPFLAGS -I$withval/include"
+# with_pth="yes"
+# fi
+#], [with_pth="no"])
+#if test "x$with_pth" = "xyes"
+#then
+# AC_CHECK_LIB(pth, pth_init,, [with_pth="no"], [])
+#fi
+#if test "x$with_pth" = "xyes"
+#then
+# AC_CHECK_HEADERS(pth.h,, [with_pth="no"])
+#fi
+#if test "x$with_pth" = "xyes"
+#then
+# collect_pth=1
+#else
+# collect_pth=0
+#fi
+#AC_DEFINE_UNQUOTED(COLLECT_PTH, [$collect_pth],
+# [Wether or not to use pth (portable threads) library])
+#AM_CONDITIONAL(BUILD_WITH_PTH, test "x$with_pth" = "xyes")
+
if test "$ac_system" = "Solaris"
then
with_kstat="yes"
#
# Check for enabled/disabled features
#
+AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug],
+ [Enable debugging (disabled by default)]),
+ [], [enable_debug="no"])
+if test "x$enable_debug" = "xno"
+then
+ collect_debug=0
+else
+ if test "x$enable_debug" = "xyes"
+ then
+ collect_debug=1
+ else
+ AC_MSG_NOTICE([Please specify either --enable-debug or --disable-debug; Enabling debugging.])
+ collect_debug=1
+ enable_debug="yes"
+ fi
+fi
+AC_DEFINE_UNQUOTED(COLLECT_DEBUG, [$collect_debug],
+ [Wether or not to enable debugging])
+AM_CONDITIONAL(BUILD_DEBUG, test "x$enable_debug" = "xyes")
+
+AC_ARG_ENABLE(daemon, AC_HELP_STRING([--disable-daemon],
+ [Disable daemon mode (enabled by default)]),
+ [], [enable_daemon="yes"])
+if test "x$enable_daemon" = "xno"
+then
+ collect_daemon=0
+else
+ if test "x$enable_daemon" = "xyes"
+ then
+ collect_daemon=1
+ else
+ AC_MSG_NOTICE([Please specify either --enable-daemon or --disable-daemon; Enabling daemon mode.])
+ collect_daemon=1
+ enable_daemon="yes"
+ fi
+fi
+AC_DEFINE_UNQUOTED(COLLECT_DAEMON, [$collect_daemon],
+ [Wether or not to enable daemon mode])
+AM_CONDITIONAL(BUILD_DAEMON, test "x$enable_daemon" = "xyes")
+
AC_ARG_ENABLE(cpu, AC_HELP_STRING([--disable-cpu], [Disable CPU usage statistics]),, [enable_cpu="yes"])
if test "x$enable_cpu" != "xno"
then
fi
AM_CONDITIONAL(BUILD_MODULE_DISK, test "x$enable_disk" = "xyes")
+AC_ARG_ENABLE(quota, AC_HELP_STRING([--enable-quota],
+ [Enable quota statistics (experimental, disabled by default)]),
+ [], [enable_quota="no"])
+if test "x$enable_quota" = "xno"
+then
+ collect_quota=0
+else
+ if test "x$enable_quota" = "xyes"
+ then
+ collect_quota=1
+ else
+ AC_MSG_NOTICE([Please specify either --enable-quota or --disable-quota; Enabling quota statistics.])
+ collect_quota=1
+ enable_quota="yes"
+ fi
+fi
+AC_DEFINE_UNQUOTED(COLLECT_QUOTA, [$collect_quota],
+ [Wether or not to collect quota statistics])
+AM_CONDITIONAL(BUILD_MODULE_QUOTA, test "x$enable_quota" = "xyes")
+
AC_ARG_ENABLE(hddtemp, AC_HELP_STRING([--disable-hddtemp], [Disable hdd temperature statistics]),, [enable_hddtemp="yes"])
if test "x$enable_hddtemp" = "xno"
then
libkstat . . . . . $with_kstat
Features:
+ debug . . . . . . . $enable_debug
+ daemon mode . . . . $enable_daemon
+
+ Modules:
cpu . . . . . . . . $enable_cpu
cpufreq . . . . . . $enable_cpufreq
disk . . . . . . . $enable_disk
+ quota . . . . . . . $enable_quota (experimental)
hddtemp . . . . . . $enable_hddtemp
load . . . . . . . $enable_load
memory . . . . . . $enable_memory
diff --git a/src/Makefile.am b/src/Makefile.am
index 75e1735f99108618e4c80bf489c6dae33271148b..fe1076b7fbddcd59266382bce86d35a13e90a14b 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
if BUILD_MODULE_PING
-SUBDIRS = libping
+SUBDIRS = libping .
endif
sbin_PROGRAMS = collectd
collectd_SOURCES = collectd.c collectd.h \
+ utils_debug.c utils_debug.h \
+ utils_mount.c utils_mount.h \
common.c common.h \
multicast.c multicast.h \
plugin.c plugin.h
#collectd_CFLAGS = -DPLUGINDIR='"$(pkglibdir)"'
collectd_CPPFLAGS = -DLOCALSTATEDIR='"$(localstatedir)"' -DPLUGINDIR='"$(pkglibdir)"'
-collectd_LDFLAGS = -dlopen self
+collectd_LDFLAGS = -export-dynamic
+collectd_CFLAGS = -Werror
+collectd_LDADD = $(LIBLTDL) "-dlopen" self
+collectd_DEPENDENCIES = $(LIBLTDL)
if BUILD_WITH_RRDTOOL
-collectd_LDFLAGS += -lrrd
+collectd_LDADD += -lrrd
endif
pkglib_LTLIBRARIES =
if BUILD_MODULE_CPU
pkglib_LTLIBRARIES += cpu.la
cpu_la_SOURCES = cpu.c cpu.h
-cpu_la_LDFLAGS = -module
+cpu_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" cpu.la
+collectd_DEPENDENCIES += cpu.la
endif
if BUILD_MODULE_CPUFREQ
pkglib_LTLIBRARIES += cpufreq.la
cpufreq_la_SOURCES = cpufreq.c cpufreq.h
-cpufreq_la_LDFLAGS = -module
+cpufreq_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" cpufreq.la
+collectd_DEPENDENCIES += cpufreq.la
endif
if BUILD_MODULE_DISK
pkglib_LTLIBRARIES += disk.la
disk_la_SOURCES = disk.c disk.h
-disk_la_LDFLAGS = -module
+disk_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" disk.la
+collectd_DEPENDENCIES += disk.la
+endif
+
+if BUILD_MODULE_QUOTA
+pkglib_LTLIBRARIES += quota.la
+quota_la_SOURCES = quota_plugin.c quota_plugin.h
+quota_la_SOURCES += quota_fs.c quota_fs.h
+quota_la_SOURCES += quota_mnt.c quota_mnt.h
+quota_la_LDFLAGS = -module -avoid-version
+quota_la_CFLAGS = -Werror
+collectd_LDADD += "-dlopen" quota.la
+collectd_DEPENDENCIES += quota.la
endif
if BUILD_MODULE_HDDTEMP
pkglib_LTLIBRARIES += hddtemp.la
hddtemp_la_SOURCES = hddtemp.c hddtemp.h
-hddtemp_la_LDFLAGS = -module
+hddtemp_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" hddtemp.la
+collectd_DEPENDENCIES += hddtemp.la
endif
if BUILD_MODULE_LOAD
pkglib_LTLIBRARIES += load.la
load_la_SOURCES = load.c load.h
-load_la_LDFLAGS = -module
+load_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" load.la
+collectd_DEPENDENCIES += load.la
endif
if BUILD_MODULE_MEMORY
pkglib_LTLIBRARIES += memory.la
memory_la_SOURCES = memory.c memory.h
-memory_la_LDFLAGS = -module
+memory_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" memory.la
+collectd_DEPENDENCIES += memory.la
endif
if BUILD_MODULE_NFS
pkglib_LTLIBRARIES += nfs.la
nfs_la_SOURCES = nfs.c nfs.h
-nfs_la_LDFLAGS = -module
+nfs_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" nfs.la
+collectd_DEPENDENCIES += nfs.la
endif
if BUILD_MODULE_PING
pkglib_LTLIBRARIES += ping.la
ping_la_SOURCES = ping.c ping.h
-ping_la_LDFLAGS = -module
+ping_la_LDFLAGS = -module -avoid-version
ping_la_LIBADD = libping/libping.la
ping_la_DEPENDENCIES = libping/libping.la
+collectd_LDADD += "-dlopen" ping.la
+collectd_DEPENDENCIES += ping.la
endif
if BUILD_MODULE_PROCESSES
pkglib_LTLIBRARIES += processes.la
processes_la_SOURCES = processes.c processes.h
-processes_la_LDFLAGS = -module
+processes_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" processes.la
+collectd_DEPENDENCIES += processes.la
endif
if BUILD_MODULE_SENSORS
pkglib_LTLIBRARIES += sensors.la
sensors_la_SOURCES = sensors.c sensors.h
-sensors_la_LDFLAGS = -module -lsensors
+sensors_la_LDFLAGS = -module -avoid-version -lsensors
+sensors_la_LIBADD = -lsensors
+collectd_LDADD += "-dlopen" sensors.la
+collectd_DEPENDENCIES += sensors.la
endif
if BUILD_MODULE_SERIAL
pkglib_LTLIBRARIES += serial.la
serial_la_SOURCES = serial.c serial.h
-serial_la_LDFLAGS = -module
+serial_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" serial.la
+collectd_DEPENDENCIES += serial.la
endif
if BUILD_MODULE_SWAP
pkglib_LTLIBRARIES += swap.la
swap_la_SOURCES = swap.c swap.h
-swap_la_LDFLAGS = -module
+swap_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" swap.la
+collectd_DEPENDENCIES += swap.la
endif
if BUILD_MODULE_TAPE
pkglib_LTLIBRARIES += tape.la
tape_la_SOURCES = tape.c tape.h
-tape_la_LDFLAGS = -module
+tape_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" tape.la
+collectd_DEPENDENCIES += tape.la
endif
if BUILD_MODULE_TRAFFIC
pkglib_LTLIBRARIES += traffic.la
traffic_la_SOURCES = traffic.c traffic.h
-traffic_la_LDFLAGS = -module
+traffic_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" traffic.la
+collectd_DEPENDENCIES += traffic.la
endif
if BUILD_MODULE_USERS
pkglib_LTLIBRARIES += users.la
users_la_SOURCES = users.c users.h
-users_la_LDFLAGS = -module
+users_la_LDFLAGS = -module -avoid-version
+collectd_LDADD += "-dlopen" users.la
+collectd_DEPENDENCIES += users.la
endif
man_MANS = collectd.1
diff --git a/src/plugin.c b/src/plugin.c
--- /dev/null
+++ b/src/plugin.c
@@ -0,0 +1,215 @@
+#include "collectd.h"
+
+#include <ltdl.h>
+
+#include "plugin.h"
+#include "multicast.h"
+
+typedef struct plugin
+{
+ char *type;
+ void (*init) (void);
+ void (*read) (void);
+ void (*write) (char *host, char *inst, char *val);
+ struct plugin *next;
+} plugin_t;
+
+static plugin_t *first_plugin = NULL;
+
+#ifdef HAVE_LIBRRD
+extern int operating_mode;
+#endif
+
+/*
+ * Returns the number of plugins registered
+ */
+int plugin_count (void)
+{
+ int i;
+ plugin_t *p;
+
+ for (i = 0, p = first_plugin; p != NULL; p = p->next)
+ i++;
+
+ return (i);
+}
+
+/*
+ * Returns the plugins with the type `type' or NULL if it's not found.
+ */
+plugin_t *plugin_search (char *type)
+{
+ plugin_t *ret;
+
+ if (type == NULL)
+ return (NULL);
+
+ for (ret = first_plugin; ret != NULL; ret = ret->next)
+ if (strcmp (ret->type, type) == 0)
+ break;
+
+ return (ret);
+}
+
+/*
+ * (Try to) load the shared object `name'. Won't complain if it isn't a shared
+ * object, but it will bitch about a shared object not having a
+ * ``module_register'' symbol..
+ */
+void plugin_load (char *name)
+{
+ lt_dlhandle dlh;
+ void (*reg_handle) (void);
+
+ lt_dlinit ();
+ lt_dlerror (); /* clear errors */
+
+ if ((dlh = lt_dlopen (name)) == NULL)
+ return;
+
+ if ((reg_handle = lt_dlsym (dlh, "module_register")) == NULL)
+ {
+ syslog (LOG_WARNING, "Couldn't find symbol ``module_register'' in ``%s'': %s\n",
+ name, lt_dlerror ());
+ lt_dlclose (dlh);
+ return;
+ }
+
+ (*reg_handle) ();
+}
+
+/*
+ * (Try to) load all plugins in `dir'. Returns the number of loaded plugins..
+ */
+#define BUFSIZE 512
+int plugin_load_all (char *dir)
+{
+ DIR *dh;
+ struct dirent *de;
+ char filename[BUFSIZE];
+ struct stat statbuf;
+
+ if (dir == NULL)
+ dir = PLUGINDIR;
+
+ if ((dh = opendir (dir)) == NULL)
+ {
+ fprintf (stderr, "Error: Cannot read plugin directory `%s'\n", dir);
+ return (0);
+ }
+
+ while ((de = readdir (dh)) != NULL)
+ {
+ if (snprintf (filename, BUFSIZE, "%s/%s", dir, de->d_name) >= BUFSIZE)
+ continue;
+
+ if (lstat (filename, &statbuf) == -1)
+ {
+ syslog (LOG_WARNING, "stat %s: %s", filename, strerror (errno));
+ continue;
+ }
+ else if (!S_ISREG (statbuf.st_mode))
+ {
+ continue;
+ }
+
+ plugin_load (filename);
+ }
+
+ closedir (dh);
+
+ return (plugin_count ());
+}
+#undef BUFSIZE
+
+/*
+ * Call `init' on all plugins (if given)
+ */
+void plugin_init_all (void)
+{
+ plugin_t *p;
+
+ for (p = first_plugin; p != NULL; p = p->next)
+ if (p->init != NULL)
+ (*p->init) ();
+}
+
+/*
+ * Call `read' on all plugins (if given)
+ */
+void plugin_read_all (void)
+{
+ plugin_t *p;
+
+ for (p = first_plugin; p != NULL; p = p->next)
+ if (p->read != NULL)
+ (*p->read) ();
+}
+
+/*
+ * Add plugin to the linked list of registered plugins.
+ */
+void plugin_register (char *type,
+ void (*init) (void),
+ void (*read) (void),
+ void (*write) (char *, char *, char *))
+{
+ plugin_t *p;
+
+ if (plugin_search (type) != NULL)
+ return;
+
+ if ((p = (plugin_t *) malloc (sizeof (plugin_t))) == NULL)
+ return;
+
+ if ((p->type = strdup (type)) == NULL)
+ {
+ free (p);
+ return;
+ }
+
+ p->init = init;
+ p->read = read;
+ p->write = write;
+
+ p->next = first_plugin;
+ first_plugin = p;
+}
+
+/*
+ * Send received data back to the plugin/module which will append DS
+ * definitions and pass it on to ``rrd_update_file''.
+ */
+#ifdef HAVE_LIBRRD
+void plugin_write (char *host, char *type, char *inst, char *val)
+{
+ plugin_t *p;
+
+ if ((p = plugin_search (type)) == NULL)
+ return;
+
+ if (p->write == NULL)
+ return;
+
+ (*p->write) (host, inst, val);
+}
+#endif /* HAVE_LIBRRD */
+
+/*
+ * Receive data from the plugin/module and get it somehow to ``plugin_write'':
+ * Either using ``multicast_send'' (when in network/client mode) or call it
+ * directly (in local mode).
+ */
+void plugin_submit (char *type, char *inst, char *val)
+{
+#ifdef HAVE_LIBRRD
+ if (operating_mode == MODE_LOCAL)
+ plugin_write (NULL, type, inst, val);
+ else if (operating_mode == MODE_CLIENT)
+ multicast_send (type, inst, val);
+ else /* operating_mode == MODE_SERVER */
+ syslog (LOG_ERR, "WTF is the server doing in ``plugin_submit''?!?\n");
+#else
+ multicast_send (type, inst, val);
+#endif
+}