X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fprocesses.c;h=beee341f6b691b4b4dd4ecee4496fcd40590f541;hb=ca4a6c8a856a9012270ec10389b08d54e70e3401;hp=4e0aa7833f0af316fed4b4586b051c49f361b5f2;hpb=1b15b227585497f72ab0e42d96d79c0313323bd4;p=collectd.git diff --git a/src/processes.c b/src/processes.c index 4e0aa783..beee341f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -287,7 +287,8 @@ static void ps_list_register (const char *name, const char *regexp) if (status != 0) { DEBUG ("ProcessMatch: compiling the regular expression \"%s\" failed.", regexp); - sfree(new->re); + sfree (new->re); + sfree (new); return; } } @@ -1031,9 +1032,9 @@ int ps_read_process (int pid, procstat_t *ps, char *state) char *fields[64]; char fields_len; - int buffer_len; + size_t buffer_len; - char *buffer_ptr; + char *buffer_ptr; size_t name_start_pos; size_t name_end_pos; size_t name_len; @@ -1044,14 +1045,16 @@ int ps_read_process (int pid, procstat_t *ps, char *state) long long unsigned vmem_rss; long long unsigned stack_size; + ssize_t status; + memset (ps, 0, sizeof (procstat_t)); ssnprintf (filename, sizeof (filename), "/proc/%i/stat", pid); - buffer_len = read_file_contents (filename, - buffer, sizeof(buffer) - 1); - if (buffer_len <= 0) + status = read_file_contents (filename, buffer, sizeof(buffer) - 1); + if (status <= 0) return (-1); + buffer_len = (size_t) status; buffer[buffer_len] = 0; /* The name of the process is enclosed in parens. Since the name can @@ -1122,7 +1125,7 @@ int ps_read_process (int pid, procstat_t *ps, char *state) /* Leave the rest at zero if this is only a zombi */ if (ps->num_proc == 0) { - DEBUG ("processes plugin: This is only a zombi: pid = %i; " + DEBUG ("processes plugin: This is only a zombie: pid = %i; " "name = %s;", pid, ps->name); return (0); } @@ -1328,16 +1331,16 @@ static const char *ps_get_cmdline (long pid, /* {{{ */ { char path[PATH_MAX]; psinfo_t info; - int status; + ssize_t status; snprintf(path, sizeof (path), "/proc/%li/psinfo", pid); status = read_file_contents (path, (void *) &info, sizeof (info)); - if (status != sizeof (info)) + if ((status < 0) || (((size_t) status) != sizeof (info))) { ERROR ("processes plugin: Unexpected return value " "while reading \"%s\": " - "Returned %i but expected %zu.", + "Returned %zd but expected %zu.", path, status, buffer_size); return (NULL); } @@ -1434,6 +1437,12 @@ static int ps_read_process(long pid, procstat_t *ps, char *state) ps->io_syscr = myUsage->pr_sysc; ps->io_syscw = myUsage->pr_sysc; + /* + * TODO: context switch counters for Solaris + */ + ps->cswitch_vol = -1; + ps->cswitch_invol = -1; + /* * TODO: Find way of setting BLOCKED and PAGING status @@ -1671,6 +1680,10 @@ static int ps_read (void) pse.cpu_user_counter = task_absolutetime_info.total_user; pse.cpu_system_counter = task_absolutetime_info.total_system; + + /* context switch counters not implemented */ + pse.cswitch_vol = -1; + pse.cswitch_invol = -1; } status = task_threads (task_list[task], &thread_list, @@ -2024,19 +2037,23 @@ static int ps_read (void) pse.io_syscr = -1; pse.io_syscw = -1; + /* context switch counters not implemented */ + pse.cswitch_vol = -1; + pse.cswitch_invol = -1; + ps_list_add (procs[i].ki_comm, have_cmdline ? cmdline : NULL, &pse); - } /* if ((proc_ptr == NULL) || (proc_ptr->ki_pid != procs[i].ki_pid)) */ - switch (procs[i].ki_stat) - { - case SSTOP: stopped++; break; - case SSLEEP: sleeping++; break; - case SRUN: running++; break; - case SIDL: idle++; break; - case SWAIT: wait++; break; - case SLOCK: blocked++; break; - case SZOMB: zombies++; break; - } + switch (procs[i].ki_stat) + { + case SSTOP: stopped++; break; + case SSLEEP: sleeping++; break; + case SRUN: running++; break; + case SIDL: idle++; break; + case SWAIT: wait++; break; + case SLOCK: blocked++; break; + case SZOMB: zombies++; break; + } + } /* if ((proc_ptr == NULL) || (proc_ptr->ki_pid != procs[i].ki_pid)) */ } kvm_close(kd); @@ -2157,22 +2174,23 @@ static int ps_read (void) pse.io_syscr = -1; pse.io_syscw = -1; - pse.cswitch_vol = -1; + /* context switch counters not implemented */ + pse.cswitch_vol = -1; pse.cswitch_invol = -1; ps_list_add (procs[i].p_comm, have_cmdline ? cmdline : NULL, &pse); - } /* if ((proc_ptr == NULL) || (proc_ptr->p_pid != procs[i].p_pid)) */ - switch (procs[i].p_stat) - { - case SSTOP: stopped++; break; - case SSLEEP: sleeping++; break; - case SRUN: running++; break; - case SIDL: idle++; break; - case SONPROC: onproc++; break; - case SDEAD: dead++; break; - case SZOMB: zombies++; break; - } + switch (procs[i].p_stat) + { + case SSTOP: stopped++; break; + case SSLEEP: sleeping++; break; + case SRUN: running++; break; + case SIDL: idle++; break; + case SONPROC: onproc++; break; + case SDEAD: dead++; break; + case SZOMB: zombies++; break; + } + } /* if ((proc_ptr == NULL) || (proc_ptr->p_pid != procs[i].p_pid)) */ } kvm_close(kd); @@ -2306,6 +2324,9 @@ static int ps_read (void) pse.io_syscr = -1; pse.io_syscw = -1; + pse.cswitch_vol = -1; + pse.cswitch_invol = -1; + ps_list_add (cmdline, cargs, &pse); } /* for (i = 0 .. nprocs) */