X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fcgroups.c;h=2584eff01edd2a71d1b7acc69f1ac02b400d49ec;hb=fa82af13503a1195e1bfaef597ac33a3dc71a758;hp=ffb1740a9846e5f134b61070a80976a8e5029879;hpb=c27675331d874c85625d2e64ebcc229db588c5f2;p=collectd.git diff --git a/src/cgroups.c b/src/cgroups.c index ffb1740a..2584eff0 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" @@ -46,7 +46,6 @@ static void cgroups_submit_one (char const *plugin_instance, vl.values = &value; vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "cgroups", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); @@ -93,7 +92,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 +110,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 +126,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 +143,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,23 +205,22 @@ 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. */ - if (strcmp(mnt_ptr->type, "cgroup") != 0 || - !cu_mount_getoptionvalue(mnt_ptr->options, "cpuacct")) + if ((strcmp(mnt_ptr->type, "cgroup") != 0) + || !cu_mount_checkoption(mnt_ptr->options, + "cpuacct", /* full = */ 1)) continue; walk_directory (mnt_ptr->dir, read_cpuacct_root,