X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdf.c;h=5b3fbd28edcc0f58c6db34bc90a53391c3675f55;hp=541660523a305bb9ccad2f1d5ca3d100b51ad184;hb=54619dc85fd308b21ed09a0271e5c7383c7921b9;hpb=45492ba3d0119874e2f2878d68089fc8f62268a4 diff --git a/src/df.c b/src/df.c index 54166052..5b3fbd28 100644 --- a/src/df.c +++ b/src/df.c @@ -23,10 +23,10 @@ #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" #if HAVE_STATVFS #if HAVE_SYS_STATVFS_H @@ -51,14 +51,14 @@ static const char *config_keys[] = { "ReportByDevice", "ReportInodes", "ValuesAbsolute", "ValuesPercentage"}; static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); -static ignorelist_t *il_device = NULL; -static ignorelist_t *il_mountpoint = NULL; -static ignorelist_t *il_fstype = NULL; +static ignorelist_t *il_device; +static ignorelist_t *il_mountpoint; +static ignorelist_t *il_fstype; -static _Bool by_device = 0; -static _Bool report_inodes = 0; -static _Bool values_absolute = 1; -static _Bool values_percentage = 0; +static bool by_device; +static bool report_inodes; +static bool values_absolute = true; +static bool values_percentage; static int df_init(void) { if (il_device == NULL) @@ -68,7 +68,7 @@ static int df_init(void) { if (il_fstype == NULL) il_fstype = ignorelist_create(1); - return (0); + return 0; } static int df_config(const char *key, const char *value) { @@ -76,16 +76,16 @@ static int df_config(const char *key, const char *value) { if (strcasecmp(key, "Device") == 0) { if (ignorelist_add(il_device, value)) - return (1); - return (0); + return 1; + return 0; } else if (strcasecmp(key, "MountPoint") == 0) { if (ignorelist_add(il_mountpoint, value)) - return (1); - return (0); + return 1; + return 0; } else if (strcasecmp(key, "FSType") == 0) { if (ignorelist_add(il_fstype, value)) - return (1); - return (0); + return 1; + return 0; } else if (strcasecmp(key, "IgnoreSelected") == 0) { if (IS_TRUE(value)) { ignorelist_set_invert(il_device, 0); @@ -96,36 +96,36 @@ static int df_config(const char *key, const char *value) { ignorelist_set_invert(il_mountpoint, 1); ignorelist_set_invert(il_fstype, 1); } - return (0); + return 0; } else if (strcasecmp(key, "ReportByDevice") == 0) { if (IS_TRUE(value)) - by_device = 1; + by_device = true; - return (0); + return 0; } else if (strcasecmp(key, "ReportInodes") == 0) { if (IS_TRUE(value)) - report_inodes = 1; + report_inodes = true; else - report_inodes = 0; + report_inodes = false; - return (0); + return 0; } else if (strcasecmp(key, "ValuesAbsolute") == 0) { if (IS_TRUE(value)) - values_absolute = 1; + values_absolute = true; else - values_absolute = 0; + values_absolute = false; - return (0); + return 0; } else if (strcasecmp(key, "ValuesPercentage") == 0) { if (IS_TRUE(value)) - values_percentage = 1; + values_percentage = true; else - values_percentage = 0; + values_percentage = false; - return (0); + return 0; } - return (-1); + return -1; } __attribute__((nonnull(2))) static void df_submit_one(char *plugin_instance, @@ -152,13 +152,14 @@ static int df_read(void) { #elif HAVE_STATFS struct statfs statbuf; #endif + int retval = 0; /* struct STATANYFS statbuf; */ cu_mount_t *mnt_list; mnt_list = NULL; if (cu_mount_getlist(&mnt_list) == NULL) { ERROR("df plugin: cu_mount_getlist failed."); - return (-1); + return -1; } for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; @@ -202,9 +203,7 @@ static int df_read(void) { continue; if (STATANYFS(mnt_ptr->dir, &statbuf) < 0) { - char errbuf[1024]; - ERROR(STATANYFS_STR "(%s) failed: %s", mnt_ptr->dir, - sstrerror(errno, errbuf, sizeof(errbuf))); + ERROR(STATANYFS_STR "(%s) failed: %s", mnt_ptr->dir, STRERRNO); continue; } @@ -226,12 +225,10 @@ static int df_read(void) { if (strcmp(mnt_ptr->dir, "/") == 0) sstrncpy(disk_name, "root", sizeof(disk_name)); else { - int len; - sstrncpy(disk_name, mnt_ptr->dir + 1, sizeof(disk_name)); - len = strlen(disk_name); + size_t len = strlen(disk_name); - for (int i = 0; i < len; i++) + for (size_t i = 0; i < len; i++) if (disk_name[i] == '/') disk_name[i] = '-'; } @@ -284,8 +281,10 @@ static int df_read(void) { (gauge_t)((float_t)(blk_reserved) / statbuf.f_blocks * 100)); df_submit_one(disk_name, "percent_bytes", "used", (gauge_t)((float_t)(blk_used) / statbuf.f_blocks * 100)); - } else - return (-1); + } else { + retval = -1; + break; + } } /* inode handling */ @@ -315,8 +314,10 @@ static int df_read(void) { df_submit_one( disk_name, "percent_inodes", "used", (gauge_t)((float_t)(inode_used) / statbuf.f_files * 100)); - } else - return (-1); + } else { + retval = -1; + break; + } } if (values_absolute) { df_submit_one(disk_name, "df_inodes", "free", (gauge_t)inode_free); @@ -329,7 +330,7 @@ static int df_read(void) { cu_mount_freelist(mnt_list); - return (0); + return retval; } /* int df_read */ void module_register(void) {