Code

Changed modules `cpu' through `sensors' to compile in `read-only' mode if dependencie...
[collectd.git] / src / cpu.c
index 67db5bcc4d7b2f8d8ab5a10d8e885ff771879051..6832b5239a1b9bad95d931b5061636e1fa01118c 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
  **/
 
 #include "collectd.h"
-#include "plugin.h"
 #include "common.h"
+#include "plugin.h"
+
+#define MODULE_NAME "cpu"
+
+#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) || defined(HAVE_SYSCTLBYNAME)
+# define CPU_HAVE_READ 1
+#else
+# define CPU_HAVE_READ 0
+#endif
 
 #ifdef HAVE_LIBKSTAT
 # include <sys/sysinfo.h>
@@ -59,8 +67,6 @@ static int numcpu;
 static int numcpu;
 #endif /* HAVE_SYSCTLBYNAME */
 
-#define MODULE_NAME "cpu"
-
 static char *cpu_filename = "cpu-%s.rrd";
 
 static char *ds_def[] =
@@ -141,6 +147,7 @@ static void cpu_submit (int cpu_num, unsigned long long user,
 }
 #undef BUFSIZE
 
+#if CPU_HAVE_READ
 static void cpu_read (void)
 {
 #ifdef KERNEL_LINUX
@@ -222,7 +229,7 @@ static void cpu_read (void)
        }
 /* #endif defined(HAVE_LIBKSTAT) */
 
-#elif defined (HAVE_SYSCTLBYNAME)
+#elif defined(HAVE_SYSCTLBYNAME)
        long cpuinfo[CPUSTATES];
        size_t cpuinfo_size;
 
@@ -242,10 +249,17 @@ static void cpu_read (void)
 
        return;
 }
+#endif /* CPU_HAVE_READ */
 
 void module_register (void)
 {
-       plugin_register (MODULE_NAME, cpu_init, cpu_read, cpu_write);
+       plugin_register (MODULE_NAME, cpu_init,
+#if CPU_HAVE_READ
+                       cpu_read,
+#else
+                       NULL,
+#endif
+                       cpu_write);
 }
 
 #undef MODULE_NAME