Code

Initialize `addrlen' before using. This might be the reason for `getnameinfo' failing..
[collectd.git] / src / processes.c
index e2bda15e41eaffdf7786048b3382b15125379116..3a7318907cd13613578d86ae36cf0e83f59c2afe 100644 (file)
@@ -33,6 +33,8 @@
 # define PROCESSES_HAVE_READ 0
 #endif
 
+#define BUFSIZE 256
+
 static char *ps_file = "processes.rrd";
 
 static char *ds_def[] =
@@ -47,17 +49,17 @@ static char *ds_def[] =
 };
 static int ds_num = 6;
 
-void ps_init (void)
+static void ps_init (void)
 {
 }
 
-void ps_write (char *host, char *inst, char *val)
+static void ps_write (char *host, char *inst, char *val)
 {
        rrd_update_file (host, ps_file, val, ds_def, ds_num);
 }
 
-#define BUFSIZE 256
-void ps_submit (unsigned int running,
+#if PROCESSES_HAVE_READ
+static void ps_submit (unsigned int running,
                unsigned int sleeping,
                unsigned int zombies,
                unsigned int stopped,
@@ -75,15 +77,14 @@ void ps_submit (unsigned int running,
        plugin_submit (MODULE_NAME, "-", buf);
 }
 
-#if PROCESSES_HAVE_READ
-void ps_read (void)
+static void ps_read (void)
 {
 #ifdef KERNEL_LINUX
        unsigned int running, sleeping, zombies, stopped, paging, blocked;
 
        char buf[BUFSIZE];
        char filename[20]; /* need 17 bytes */
-       char *fields[256];
+       char *fields[BUFSIZE];
 
        struct dirent *ent;
        DIR *proc;
@@ -119,7 +120,7 @@ void ps_read (void)
 
                fclose (fh);
 
-               if (strsplit (buf, fields, 256) < 3)
+               if (strsplit (buf, fields, BUFSIZE) < 3)
                        continue;
 
                switch (fields[2][0])
@@ -138,18 +139,14 @@ void ps_read (void)
        ps_submit (running, sleeping, zombies, stopped, paging, blocked);
 #endif /* defined(KERNEL_LINUX) */
 }
+#else
+# define ps_read NULL
 #endif /* PROCESSES_HAVE_READ */
-#undef BUFSIZE
 
 void module_register (void)
 {
-       plugin_register (MODULE_NAME, ps_init,
-#if PROCESSES_HAVE_READ
-                       ps_read,
-#else
-                       NULL,
-#endif
-                       ps_write);
+       plugin_register (MODULE_NAME, ps_init, ps_read, ps_write);
 }
 
+#undef BUFSIZE
 #undef MODULE_NAME