X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdisk.c;h=206862baab4ebea4cfa809a7e4e57774e7be5a5a;hp=4a217c30ff58dca99bd6c00343a3469df13d7245;hb=d486225f89ea52d8ed2b4242eba2ad94c409f837;hpb=b165cd13cd30a30ac830df1f6f6fbd52474a6f64 diff --git a/src/disk.c b/src/disk.c index 4a217c30..206862ba 100644 --- a/src/disk.c +++ b/src/disk.c @@ -82,7 +82,7 @@ static mach_port_t io_master_port = MACH_PORT_NULL; /* This defaults to false for backwards compatibility. Please fix in the next * major version. */ -static _Bool use_bsd_name = 0; +static bool use_bsd_name; /* #endif HAVE_IOKIT_IOKITLIB_H */ #elif KERNEL_LINUX @@ -106,9 +106,9 @@ typedef struct diskstats { derive_t avg_read_time; derive_t avg_write_time; - _Bool has_merged; - _Bool has_in_progress; - _Bool has_io_time; + bool has_merged; + bool has_in_progress; + bool has_io_time; struct diskstats *next; } diskstats_t; @@ -120,10 +120,13 @@ static struct gmesh geom_tree; /* #endif KERNEL_FREEBSD */ #elif HAVE_LIBKSTAT +#if HAVE_KSTAT_H +#include +#endif #define MAX_NUMDISK 1024 extern kstat_ctl_t *kc; static kstat_t *ksp[MAX_NUMDISK]; -static int numdisk = 0; +static int numdisk; /* #endif HAVE_LIBKSTAT */ #elif defined(HAVE_LIBSTATGRAB) @@ -139,10 +142,10 @@ static int pnumdisk; #error "No applicable input method." #endif -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H #include -static char *conf_udev_name_attr = NULL; +static char *conf_udev_name_attr; static struct udev *handle_udev; #endif @@ -150,7 +153,7 @@ static const char *config_keys[] = {"Disk", "UseBSDName", "IgnoreSelected", "UdevNameAttr"}; static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); -static ignorelist_t *ignorelist = NULL; +static ignorelist_t *ignorelist; static int disk_config(const char *key, const char *value) { if (ignorelist == NULL) @@ -167,13 +170,13 @@ static int disk_config(const char *key, const char *value) { ignorelist_set_invert(ignorelist, invert); } else if (strcasecmp("UseBSDName", key) == 0) { #if HAVE_IOKIT_IOKITLIB_H - use_bsd_name = IS_TRUE(value) ? 1 : 0; + use_bsd_name = IS_TRUE(value); #else WARNING("disk plugin: The \"UseBSDName\" option is only supported " "on Mach / Mac OS X and will be ignored."); #endif } else if (strcasecmp("UdevNameAttr", key) == 0) { -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H if (conf_udev_name_attr != NULL) { free(conf_udev_name_attr); conf_udev_name_attr = NULL; @@ -209,7 +212,7 @@ static int disk_init(void) { /* #endif HAVE_IOKIT_IOKITLIB_H */ #elif KERNEL_LINUX -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H if (conf_udev_name_attr != NULL) { handle_udev = udev_new(); if (handle_udev == NULL) { @@ -217,7 +220,7 @@ static int disk_init(void) { return -1; } } -#endif /* HAVE_UDEV_H */ +#endif /* HAVE_LIBUDEV_H */ /* #endif KERNEL_LINUX */ #elif KERNEL_FREEBSD @@ -260,10 +263,10 @@ static int disk_init(void) { static int disk_shutdown(void) { #if KERNEL_LINUX -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H if (handle_udev != NULL) udev_unref(handle_udev); -#endif /* HAVE_UDEV_H */ +#endif /* HAVE_LIBUDEV_H */ #endif /* KERNEL_LINUX */ return 0; } /* int disk_shutdown */ @@ -325,7 +328,7 @@ static counter_t disk_calc_time_incr(counter_t delta_time, } #endif -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H /** * Attempt to provide an rename disk instance from an assigned udev attribute. * @@ -405,8 +408,8 @@ static int disk_read(void) { /* Get the list of all disk objects. */ if (IOServiceGetMatchingServices( - io_master_port, IOServiceMatching(kIOBlockStorageDriverClass), - &disk_list) != kIOReturnSuccess) { + io_master_port, IOServiceMatching(kIOBlockStorageDriverClass), + &disk_list) != kIOReturnSuccess) { ERROR("disk plugin: IOServiceGetMatchingServices failed."); return -1; } @@ -490,11 +493,10 @@ static int disk_read(void) { sstrncpy(disk_name, props_disk_name_bsd, sizeof(disk_name)); else { ERROR("disk plugin: can't find bsd disk name."); - ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, - disk_minor); + snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); } } else - ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); + snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor); DEBUG("disk plugin: disk_name = \"%s\"", disk_name); @@ -815,13 +817,13 @@ static int disk_read(void) { ds->write_time = write_time; if (read_merged || write_merged) - ds->has_merged = 1; + ds->has_merged = true; if (in_progress) - ds->has_in_progress = 1; + ds->has_in_progress = true; if (io_time) - ds->has_io_time = 1; + ds->has_io_time = true; } /* if (is_disk) */ @@ -842,7 +844,7 @@ static int disk_read(void) { output_name = disk_name; -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H char *alt_name = NULL; if (conf_udev_name_attr != NULL) { alt_name = @@ -853,7 +855,7 @@ static int disk_read(void) { #endif if (ignorelist_match(ignorelist, output_name) != 0) { -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H /* release udev-based alternate name, if allocated */ sfree(alt_name); #endif @@ -879,7 +881,7 @@ static int disk_read(void) { submit_io_time(output_name, io_time, weighted_time); } /* if (is_disk) */ -#if HAVE_UDEV_H +#if HAVE_LIBUDEV_H /* release udev-based alternate name, if allocated */ sfree(alt_name); #endif @@ -974,9 +976,7 @@ static int disk_read(void) { int rnumdisk; if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0) { - char errbuf[1024]; - WARNING("disk plugin: perfstat_disk: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("disk plugin: perfstat_disk: %s", STRERRNO); return -1; } @@ -990,9 +990,7 @@ static int disk_read(void) { firstpath.name[0] = '\0'; if ((rnumdisk = perfstat_disk(&firstpath, stat_disk, sizeof(perfstat_disk_t), numdisk)) < 0) { - char errbuf[1024]; - WARNING("disk plugin: perfstat_disk : %s", - sstrerror(errno, errbuf, sizeof(errbuf))); + WARNING("disk plugin: perfstat_disk : %s", STRERRNO); return -1; }