X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fprocesses.c;h=bab7080faa753eb8c80605bef8712dfe41b560a4;hb=61a1fa91ba73e4fe3a34949f77c5f017056f2b7a;hp=e37e566ae4ad4b3202f56fa4bd03b7f7d2df547b;hpb=dbb051d5f8c59c1c52070fb1a25f0fa3ab479b8d;p=collectd.git diff --git a/src/processes.c b/src/processes.c index e37e566a..bab7080f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -6,6 +6,7 @@ * Copyright (C) 2009 Sebastian Harl * Copyright (C) 2009 Andrés J. Díaz * Copyright (C) 2009 Manuel Sanmartin + * Copyright (C) 2010 Clément Stenac * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -28,6 +29,7 @@ * Sebastian Harl * Andrés J. Díaz * Manuel Sanmartin + * Clément Stenac **/ #include "collectd.h" @@ -119,8 +121,6 @@ # define ARG_MAX 4096 #endif -#define BUFSIZE 256 - static const char *config_keys[] = { "Process", @@ -759,15 +759,16 @@ static procstat_t *ps_read_vmem (int pid, procstat_t *ps) if ((fh = fopen (filename, "r")) == NULL) return (NULL); - while (fgets (buffer, 1024, fh) != NULL) + while (fgets (buffer, sizeof(buffer), fh) != NULL) { long long tmp; char *endptr; - if (strncasecmp (buffer, "Vm", 2) != 0) + if (strncmp (buffer, "Vm", 2) != 0) continue; - numfields = strsplit (buffer, fields, 8); + numfields = strsplit (buffer, fields, + STATIC_ARRAY_SIZE (fields)); if (numfields < 2) continue; @@ -818,7 +819,7 @@ static procstat_t *ps_read_io (int pid, procstat_t *ps) if ((fh = fopen (filename, "r")) == NULL) return (NULL); - while (fgets (buffer, 1024, fh) != NULL) + while (fgets (buffer, sizeof (buffer), fh) != NULL) { derive_t *val = NULL; long long tmp; @@ -835,7 +836,8 @@ static procstat_t *ps_read_io (int pid, procstat_t *ps) else continue; - numfields = strsplit (buffer, fields, 8); + numfields = strsplit (buffer, fields, + STATIC_ARRAY_SIZE (fields)); if (numfields < 2) continue; @@ -869,7 +871,6 @@ int ps_read_process (int pid, procstat_t *ps, char *state) int i; - int ppid; int name_len; long long unsigned cpu_user_counter; @@ -887,7 +888,7 @@ int ps_read_process (int pid, procstat_t *ps, char *state) return (-1); buffer[i] = 0; - fields_len = strsplit (buffer, fields, 64); + fields_len = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields)); if (fields_len < 24) { DEBUG ("processes plugin: ps_read_process (pid = %i):" @@ -907,7 +908,6 @@ int ps_read_process (int pid, procstat_t *ps, char *state) fields[1][name_len] = '\0'; strncpy (ps->name, fields[1], PROCSTAT_NAME_LEN); - ppid = atoi (fields[3]); *state = fields[2][0]; @@ -997,13 +997,18 @@ static char *ps_get_cmdline (pid_t pid, char *name, char *buf, size_t buf_len) if ((pid < 1) || (NULL == buf) || (buf_len < 2)) return NULL; - ssnprintf (file, sizeof (file), "/proc/%u/cmdline", pid); + ssnprintf (file, sizeof (file), "/proc/%u/cmdline", + (unsigned int) pid); + errno = 0; fd = open (file, O_RDONLY); if (fd < 0) { char errbuf[4096]; - WARNING ("processes plugin: Failed to open `%s': %s.", file, - sstrerror (errno, errbuf, sizeof (errbuf))); + /* ENOENT means the process exited while we were handling it. + * Don't complain about this, it only fills the logs. */ + if (errno != ENOENT) + WARNING ("processes plugin: Failed to open `%s': %s.", file, + sstrerror (errno, errbuf, sizeof (errbuf))); return NULL; } @@ -1018,7 +1023,7 @@ static char *ps_get_cmdline (pid_t pid, char *name, char *buf, size_t buf_len) status = read (fd, (void *)buf_ptr, len); if (status < 0) { - char errbuf[4096]; + char errbuf[1024]; if ((EAGAIN == errno) || (EINTR == errno)) continue; @@ -1103,7 +1108,7 @@ static unsigned long read_fork_rate () errno = 0; endptr = NULL; - result = strtoul(fields[1], &endptr, 10); + result = strtoul(fields[1], &endptr, /* base = */ 10); if ((endptr == fields[1]) || (errno != 0)) { ERROR ("processes plugin: Cannot parse fork rate: %s", fields[1]); @@ -1302,6 +1307,7 @@ static int ps_read (void) } pse.num_proc++; + pse.vmem_size = task_basic_info.virtual_size; pse.vmem_rss = task_basic_info.resident_size; /* Does not seem to be easily exposed */ pse.vmem_data = 0; @@ -1586,9 +1592,9 @@ static int ps_read (void) procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, &count); if (procs == NULL) { - kvm_close (kd); ERROR ("processes plugin: Cannot get kvm processes list: %s", kvm_geterr(kd)); + kvm_close (kd); return (0); } @@ -1794,6 +1800,11 @@ static int ps_read (void) pse.vmem_code = 0; pse.stack_size = 0; + pse.io_rchar = -1; + pse.io_wchar = -1; + pse.io_syscr = -1; + pse.io_syscw = -1; + ps_list_add (cmdline, cargs, &pse); } /* for (i = 0 .. nprocs) */