X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcgroups.c;h=f7c7e0d6345676ab77c79d8c6f0a880331b75273;hb=4d370741101aeb037ae52f3529a4a0869e0dc08a;hp=a515cf5b0c62511d97cf39a18fcd864c0cee621d;hpb=57bd4c578e337319d4a190311bb08ef98d0d7358;p=collectd.git diff --git a/src/cgroups.c b/src/cgroups.c index a515cf5b..f7c7e0d6 100644 --- a/src/cgroups.c +++ b/src/cgroups.c @@ -22,9 +22,9 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include "utils_mount.h" #include "utils_ignorelist.h" @@ -93,7 +93,7 @@ static int read_cpuacct_procs (const char *dirname, char const *cgroup_name, if (fh == NULL) { char errbuf[1024]; - ERROR ("cgroups pluign: fopen (\"%s\") failed: %s", + ERROR ("cgroups plugin: fopen (\"%s\") failed: %s", abs_path, sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); @@ -111,6 +111,11 @@ static int read_cpuacct_procs (const char *dirname, char const *cgroup_name, * * user: 12345 * system: 23456 + * + * Or: + * + * user 12345 + * system 23456 */ strstripnewline (buf); numfields = strsplit (buf, fields, STATIC_ARRAY_SIZE (fields)); @@ -122,10 +127,9 @@ static int read_cpuacct_procs (const char *dirname, char const *cgroup_name, if (key_len < 2) continue; - /* Strip colon off the first column */ - if (key[key_len - 1] != ':') - continue; - key[key_len - 1] = 0; + /* Strip colon off the first column, if found */ + if (key[key_len - 1] == ':') + key[key_len - 1] = 0; status = parse_value (fields[1], &value, DS_TYPE_DERIVE); if (status != 0) @@ -140,7 +144,7 @@ static int read_cpuacct_procs (const char *dirname, char const *cgroup_name, /* * Gets called for every file/folder in /sys/fs/cgroup/cpu,cpuacct (or - * whereever cpuacct is mounted on the system). Calls walk_directory with the + * wherever cpuacct is mounted on the system). Calls walk_directory with the * read_cpuacct_procs callback on every folder it finds, such as "system". */ static int read_cpuacct_root (const char *dirname, const char *filename, @@ -202,18 +206,16 @@ static int cgroups_config (const char *key, const char *value) static int cgroups_read (void) { - cu_mount_t *mnt_list; - cu_mount_t *mnt_ptr; + cu_mount_t *mnt_list = NULL; _Bool cgroup_found = 0; - mnt_list = NULL; if (cu_mount_getlist (&mnt_list) == NULL) { ERROR ("cgroups plugin: cu_mount_getlist failed."); return (-1); } - for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) + for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next) { /* Find the cgroup mountpoint which contains the cpuacct * controller. */