X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fprocesses.c;h=bab7080faa753eb8c80605bef8712dfe41b560a4;hb=61a1fa91ba73e4fe3a34949f77c5f017056f2b7a;hp=8a3df644d00e71be94f343faaa65c3b29bd9aafb;hpb=97addf1e406c75be500ae020635f3cb389f206e0;p=collectd.git diff --git a/src/processes.c b/src/processes.c index 8a3df644..bab7080f 100644 --- a/src/processes.c +++ b/src/processes.c @@ -871,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; @@ -909,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]; @@ -999,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; } @@ -1020,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; @@ -1589,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); }