X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fcgroups.c;h=8925239848f0ba2af42d50e92b6a5224fc050540;hp=3f7d4f414592e6823a27f88d368c4164e57bdce3;hb=48efd3deb4c9139fd060ff3d289896e9031bcc7c;hpb=cd401b9728839f8b24fd16fac9e9c1753526fd4e diff --git a/src/cgroups.c b/src/cgroups.c index 3f7d4f41..89252398 100644 --- a/src/cgroups.c +++ b/src/cgroups.c @@ -23,15 +23,15 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" -#include "utils_ignorelist.h" -#include "utils_mount.h" +#include "utils/common/common.h" +#include "utils/ignorelist/ignorelist.h" +#include "utils/mount/mount.h" static char const *config_keys[] = {"CGroup", "IgnoreSelected"}; static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); -static ignorelist_t *il_cgroup = NULL; +static ignorelist_t *il_cgroup; __attribute__((nonnull(1))) __attribute__((nonnull(2))) static void cgroups_submit_one(char const *plugin_instance, char const *type_instance, @@ -61,28 +61,26 @@ static int read_cpuacct_procs(const char *dirname, char const *cgroup_name, FILE *fh; if (ignorelist_match(il_cgroup, cgroup_name)) - return (0); + return 0; - ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, cgroup_name); + snprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, cgroup_name); status = lstat(abs_path, &statbuf); if (status != 0) { ERROR("cgroups plugin: stat (\"%s\") failed.", abs_path); - return (-1); + return -1; } /* We are only interested in directories, so skip everything else. */ if (!S_ISDIR(statbuf.st_mode)) - return (0); + return 0; - ssnprintf(abs_path, sizeof(abs_path), "%s/%s/cpuacct.stat", dirname, - cgroup_name); + snprintf(abs_path, sizeof(abs_path), "%s/%s/cpuacct.stat", dirname, + cgroup_name); fh = fopen(abs_path, "r"); if (fh == NULL) { - char errbuf[1024]; - ERROR("cgroups plugin: fopen (\"%s\") failed: %s", abs_path, - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + ERROR("cgroups plugin: fopen (\"%s\") failed: %s", abs_path, STRERRNO); + return -1; } while (fgets(buf, sizeof(buf), fh) != NULL) { @@ -114,7 +112,7 @@ static int read_cpuacct_procs(const char *dirname, char const *cgroup_name, /* Strip colon off the first column, if found */ if (key[key_len - 1] == ':') - key[key_len - 1] = 0; + key[key_len - 1] = '\0'; status = parse_value(fields[1], &value, DS_TYPE_DERIVE); if (status != 0) @@ -124,7 +122,7 @@ static int read_cpuacct_procs(const char *dirname, char const *cgroup_name, } fclose(fh); - return (0); + return 0; } /* int read_cpuacct_procs */ /* @@ -138,29 +136,29 @@ static int read_cpuacct_root(const char *dirname, const char *filename, struct stat statbuf; int status; - ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename); + snprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename); status = lstat(abs_path, &statbuf); if (status != 0) { ERROR("cgroups plugin: stat (%s) failed.", abs_path); - return (-1); + return -1; } if (S_ISDIR(statbuf.st_mode)) { status = walk_directory(abs_path, read_cpuacct_procs, /* user_data = */ NULL, /* include_hidden = */ 0); - return (status); + return status; } - return (0); + return 0; } static int cgroups_init(void) { if (il_cgroup == NULL) il_cgroup = ignorelist_create(1); - return (0); + return 0; } static int cgroups_config(const char *key, const char *value) { @@ -168,26 +166,26 @@ static int cgroups_config(const char *key, const char *value) { if (strcasecmp(key, "CGroup") == 0) { if (ignorelist_add(il_cgroup, value)) - return (1); - return (0); + return 1; + return 0; } else if (strcasecmp(key, "IgnoreSelected") == 0) { if (IS_TRUE(value)) ignorelist_set_invert(il_cgroup, 0); else ignorelist_set_invert(il_cgroup, 1); - return (0); + return 0; } - return (-1); + return -1; } static int cgroups_read(void) { cu_mount_t *mnt_list = NULL; - _Bool cgroup_found = 0; + bool cgroup_found = false; if (cu_mount_getlist(&mnt_list) == NULL) { ERROR("cgroups plugin: cu_mount_getlist failed."); - return (-1); + return -1; } for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; @@ -201,7 +199,7 @@ static int cgroups_read(void) { walk_directory(mnt_ptr->dir, read_cpuacct_root, /* user_data = */ NULL, /* include_hidden = */ 0); - cgroup_found = 1; + cgroup_found = true; /* It doesn't make sense to check other cpuacct mount-points * (if any), they contain the same data. */ break; @@ -212,10 +210,10 @@ static int cgroups_read(void) { if (!cgroup_found) { WARNING("cgroups plugin: Unable to find cgroup " "mount-point with the \"cpuacct\" option."); - return (-1); + return -1; } - return (0); + return 0; } /* int cgroup_read */ void module_register(void) {