collectd.conf(5): Added a note about that trailing whitespace bug.
[collectd.git] / src / processes.c
index c8f3016..4b59351 100644 (file)
@@ -144,12 +144,14 @@ static char *ps_pagefaults_ds_def[] =
 };
 static int ps_pagefaults_ds_num = 2;
 
+#if HAVE_THREAD_INFO | KERNEL_LINUX
 static char *config_keys[] =
 {
        "Process",
        NULL
 };
 static int config_keys_num = 1;
+#endif
 
 typedef struct procstat_entry_s
 {
@@ -192,7 +194,9 @@ typedef struct procstat
        struct procstat_entry_s *instances;
 } procstat_t;
 
+#if HAVE_THREAD_INFO | KERNEL_LINUX
 static procstat_t *list_head_g = NULL;
+#endif
 
 #if HAVE_THREAD_INFO
 static mach_port_t port_host_self;
@@ -403,7 +407,6 @@ static void ps_list_reset (void)
                } /* while (pse != NULL) */
        } /* for (ps = list_head_g; ps != NULL; ps = ps->next) */
 }
-#endif /* HAVE_THREAD_INFO | KERNEL_LINUX */
 
 static int ps_config (char *key, char *value)
 {
@@ -418,6 +421,7 @@ static int ps_config (char *key, char *value)
 
        return (0);
 }
+#endif /* HAVE_THREAD_INFO | KERNEL_LINUX */
 
 static void ps_init (void)
 {
@@ -638,11 +642,14 @@ static int *ps_read_tasks (int pid)
 
        closedir (dh);
 
+       if (list_len == 0)
+               return (NULL);
+
        assert (list_len < list_size);
        assert (list[list_len] == 0);
 
        return (list);
-}
+} /* int *ps_read_tasks */
 
 int ps_read_process (int pid, procstat_t *ps, char *state)
 {
@@ -704,17 +711,21 @@ int ps_read_process (int pid, procstat_t *ps, char *state)
 
        ppid = atoi (fields[3]);
 
-       if ((tasks = ps_read_tasks (pid)) == NULL)
-       {
-               /* This happends for zombied, e.g. */
-               DBG ("ps_read_tasks (%i) failed.", pid);
-               *state = 'Z';
-               ps->num_lwp  = 0;
-               ps->num_proc = 0;
-       }
+       *state = fields[2][0];
+       if (*state == 'Z')
+       {
+               ps->num_lwp  = 0;
+               ps->num_proc = 0;
+       }
+       else if ((tasks = ps_read_tasks (pid)) == NULL)
+       {
+               /* Kernel 2.4 or so */
+               ps->num_lwp  = 1;
+               ps->num_proc = 1;
+       }
        else
        {
-               *state = '\0';
                ps->num_lwp  = 0;
                ps->num_proc = 1;
                for (i = 0; tasks[i] != 0; i++)
@@ -724,10 +735,10 @@ int ps_read_process (int pid, procstat_t *ps, char *state)
                tasks = NULL;
        }
 
-       /* Leave the rest at zero if this is only an LWP */
+       /* Leave the rest at zero if this is only a zombi */
        if (ps->num_proc == 0)
        {
-               DBG ("This is only an LWP: pid = %i; name = %s;",
+               DBG ("This is only a zombi: pid = %i; name = %s;",
                                pid, ps->name);
                return (0);
        }
@@ -747,8 +758,6 @@ int ps_read_process (int pid, procstat_t *ps, char *state)
        ps->cpu_system_counter = (unsigned long) cpu_system_counter;
        ps->vmem_rss = (unsigned long) vmem_rss;
 
-       *state = fields[2][0];
-
        /* success */
        return (0);
 } /* int ps_read_process (...) */
@@ -1135,7 +1144,9 @@ void module_register (void)
        plugin_register ("ps_cputime", NULL, NULL, ps_cputime_write);
        plugin_register ("ps_count", NULL, NULL, ps_count_write);
        plugin_register ("ps_pagefaults", NULL, NULL, ps_pagefaults_write);
+#if HAVE_THREAD_INFO | KERNEL_LINUX
        cf_register (MODULE_NAME, ps_config, config_keys, config_keys_num);
+#endif
 }
 
 #undef BUFSIZE