perl plugin: Exported plugin_log() to Perl.
[collectd.git] / src / vserver.c
index 00a1e6a..2e39060 100644 (file)
 #include "plugin.h"
 
 #include <dirent.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <syslog.h>
 #include <sys/types.h>
-#include <unistd.h>
 
 #define BUFSIZE 512
 
@@ -183,17 +178,14 @@ static int vserver_read (void)
        DIR                     *proc;
        struct dirent   *dent; /* 42 */
 
-       static complain_t complain_obj;
-
        errno = 0;
        if (NULL == (proc = opendir (PROCDIR)))
        {
-               plugin_complain (LOG_ERR, &complain_obj, "vserver plugin: "
-                               "fopen (%s) failed: %s", PROCDIR, strerror (errno));
+               char errbuf[1024];
+               ERROR ("vserver plugin: fopen (%s): %s", PROCDIR, 
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
                return (-1);
        }
-       plugin_relief (LOG_NOTICE, &complain_obj, "vserver plugin: "
-                       "fopen (%s) succeeded.", PROCDIR);
 
        while (NULL != (dent = readdir (proc)))
        {
@@ -218,7 +210,11 @@ static int vserver_read (void)
                        continue;
 
                if (NULL == (fh = fopen (file, "r")))
-                       syslog (LOG_ERR, "Cannot open '%s': %s", file, strerror (errno));
+               {
+                       char errbuf[1024];
+                       ERROR ("Cannot open '%s': %s", file,
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+               }
 
                while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh)))
                {
@@ -261,7 +257,11 @@ static int vserver_read (void)
                        continue;
 
                if (NULL == (fh = fopen (file, "r")))
-                       syslog (LOG_ERR, "Cannot open '%s': %s", file, strerror (errno));
+               {
+                       char errbuf[1024];
+                       ERROR ("Cannot open '%s': %s", file,
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+               }
 
                while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh)))
                {
@@ -309,7 +309,11 @@ static int vserver_read (void)
                        continue;
 
                if (NULL == (fh = fopen (file, "r")))
-                       syslog (LOG_ERR, "Cannot open '%s': %s", file, strerror (errno));
+               {
+                       char errbuf[1024];
+                       ERROR ("Cannot open '%s': %s", file,
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
+               }
 
                while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh)))
                {
@@ -358,17 +362,23 @@ static int vserver_read (void)
 } /* int vserver_read */
 #endif /* VSERVER_HAVE_READ */
 
-void module_register (void)
+void module_register (modreg_e load)
 {
-       plugin_register_data_set (&octets_ds);
-       plugin_register_data_set (&load_ds);
-       plugin_register_data_set (&threads_ds);
-       plugin_register_data_set (&processes_ds);
-       plugin_register_data_set (&memory_ds);
+       if (load & MR_DATASETS)
+       {
+               plugin_register_data_set (&octets_ds);
+               plugin_register_data_set (&load_ds);
+               plugin_register_data_set (&threads_ds);
+               plugin_register_data_set (&processes_ds);
+               plugin_register_data_set (&memory_ds);
+       }
 
 #if VSERVER_HAVE_READ
-       plugin_register_init ("vserver", vserver_init);
-       plugin_register_read ("vserver", vserver_read);
+       if (load & MR_READ)
+       {
+               plugin_register_init ("vserver", vserver_init);
+               plugin_register_read ("vserver", vserver_read);
+       }
 #endif /* VSERVER_HAVE_READ */
 } /* void module_register(void) */