X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fprocesses.c;h=9d8bc01d468eb088c65845e119dde4d9c4584d1f;hb=747f853a2ce3f8a55438aff274df5ea25a3e9cce;hp=5a29236d8970bdac405775e939b1ca5bf41b4bf4;hpb=e1b0c447f57338706d45a485b40da7325faa4f34;p=collectd.git diff --git a/src/processes.c b/src/processes.c index 5a29236d..9d8bc01d 100644 --- a/src/processes.c +++ b/src/processes.c @@ -80,27 +80,20 @@ # ifndef CONFIG_HZ # define CONFIG_HZ 100 # endif -#endif /* KERNEL_LINUX */ - -#define MODULE_NAME "processes" +/* #endif KERNEL_LINUX */ -#if HAVE_THREAD_INFO || KERNEL_LINUX -# define PROCESSES_HAVE_READ 1 #else -# define PROCESSES_HAVE_READ 0 +# error "No applicable input method." #endif #define BUFSIZE 256 -#if PROCESSES_HAVE_READ -#if HAVE_THREAD_INFO | KERNEL_LINUX static const char *config_keys[] = { "Process", NULL }; static int config_keys_num = 1; -#endif typedef struct procstat_entry_s { @@ -143,9 +136,7 @@ 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; @@ -159,7 +150,6 @@ static mach_msg_type_number_t pset_list_len; static long pagesize_g; #endif /* KERNEL_LINUX */ -#if HAVE_THREAD_INFO | KERNEL_LINUX static void ps_list_register (const char *name) { procstat_t *new; @@ -370,7 +360,6 @@ static int ps_config (const char *key, const char *value) return (0); } -#endif /* HAVE_THREAD_INFO | KERNEL_LINUX */ static int ps_init (void) { @@ -521,11 +510,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) { @@ -584,17 +576,21 @@ int ps_read_process (int pid, procstat_t *ps, char *state) ppid = atoi (fields[3]); - if ((tasks = ps_read_tasks (pid)) == NULL) + *state = fields[2][0]; + + if (*state == 'Z') { - /* This happends for zombied, e.g. */ - DEBUG ("ps_read_tasks (%i) failed.", pid); - *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++) @@ -604,10 +600,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) { - DEBUG ("This is only an LWP: pid = %i; name = %s;", + DEBUG ("This is only a zombi: pid = %i; name = %s;", pid, ps->name); return (0); } @@ -627,8 +623,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 (...) */ @@ -1016,16 +1010,11 @@ static int ps_read (void) return (0); } /* int ps_read */ -#endif /* PROCESSES_HAVE_READ */ void module_register (void) { -#if PROCESSES_HAVE_READ -#if HAVE_THREAD_INFO | KERNEL_LINUX plugin_register_config ("processes", ps_config, config_keys, config_keys_num); -#endif plugin_register_init ("processes", ps_init); plugin_register_read ("processes", ps_read); -#endif /* PROCESSES_HAVE_READ */ } /* void module_register */