From d080d85ee8dd61dedd223ac68856230b3483c448 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 25 Jun 2006 10:42:32 +0200 Subject: [PATCH] Applied all the changes that `git-svnimport' missed. --- configure.in | 4 - contrib/collection.cgi | 43 +++---- src/Makefile.am | 3 - src/battery.c | 294 ++++++++++++++++-------------------------------- src/disk.c | 250 ++-------------------------------------- src/liboping/liboping.c | 77 +------------ src/liboping/liboping.h | 28 ++++- src/ping.c | 9 +- 8 files changed, 149 insertions(+), 559 deletions(-) diff --git a/configure.in b/configure.in index f2573a32..370f5b26 100644 --- a/configure.in +++ b/configure.in @@ -174,10 +174,6 @@ AC_CHECK_HEADERS(IOKit/ps/IOPowerSources.h, [], [], ]) AC_CHECK_HEADERS(IOKit/ps/IOPSKeys.h) -# For the `disk' plugin -AC_CHECK_HEADERS(IOKit/IOBSD.h) -AC_CHECK_HEADERS(IOKit/storage/IOBlockStorageDriver.h) - # For load module AC_CHECK_HEADERS(sys/loadavg.h) diff --git a/contrib/collection.cgi b/contrib/collection.cgi index 95102b53..51e187de 100755 --- a/contrib/collection.cgi +++ b/contrib/collection.cgi @@ -235,18 +235,6 @@ our $GraphDefs; 'GPRINT:total_max_ms:MAX:%5.1lf%s Max,', 'GPRINT:total_avg_ms:LAST:%5.1lf%s Last' ], - fanspeed => [ - 'DEF:temp_avg={file}:value:AVERAGE', - 'DEF:temp_min={file}:value:MIN', - 'DEF:temp_max={file}:value:MAX', - "AREA:temp_max#$HalfBlue", - "AREA:temp_min#$Canvas", - "LINE1:temp_avg#$FullBlue:RPM", - 'GPRINT:temp_min:MIN:%4.1lf Min,', - 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,', - 'GPRINT:temp_max:MAX:%4.1lf Max,', - 'GPRINT:temp_avg:LAST:%4.1lf Last\l' - ], hddtemp => [ 'DEF:temp_avg={file}:value:AVERAGE', 'DEF:temp_min={file}:value:MIN', @@ -647,6 +635,18 @@ our $GraphDefs; 'GPRINT:sleeping_max:MAX:%5.1lf Max,', 'GPRINT:sleeping_avg:LAST:%5.1lf Last\l' ], + sensors => [ + 'DEF:temp_avg={file}:value:AVERAGE', + 'DEF:temp_min={file}:value:MIN', + 'DEF:temp_max={file}:value:MAX', + "AREA:temp_max#$HalfBlue", + "AREA:temp_min#$Canvas", + "LINE1:temp_avg#$FullBlue:Value", + 'GPRINT:temp_min:MIN:%4.1lf Min,', + 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,', + 'GPRINT:temp_max:MAX:%4.1lf Max,', + 'GPRINT:temp_avg:LAST:%4.1lf Last\l' + ], swap => [ 'DEF:used_avg={file}:used:AVERAGE', 'DEF:used_min={file}:used:MIN', @@ -691,18 +691,6 @@ our $GraphDefs; 'GPRINT:used_max:MAX:%5.1lf%s Max,', 'GPRINT:used_avg:LAST:%5.1lf%s Last\l' ], - temperature => [ - 'DEF:temp_avg={file}:value:AVERAGE', - 'DEF:temp_min={file}:value:MIN', - 'DEF:temp_max={file}:value:MAX', - "AREA:temp_max#$HalfBlue", - "AREA:temp_min#$Canvas", - "LINE1:temp_avg#$FullBlue:Value", - 'GPRINT:temp_min:MIN:%4.1lf Min,', - 'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,', - 'GPRINT:temp_max:MAX:%4.1lf Max,', - 'GPRINT:temp_avg:LAST:%4.1lf Last\l' - ], traffic => ['DEF:out_min_raw={file}:outgoing:MIN', 'DEF:out_avg_raw={file}:outgoing:AVERAGE', 'DEF:out_max_raw={file}:outgoing:MAX', @@ -857,7 +845,6 @@ our $GraphDefs; }; $GraphDefs->{'disk'} = $GraphDefs->{'partition'}; $GraphDefs->{'meminfo'} = $GraphDefs->{'memory'}; - $GraphDefs->{'sensors'} = $GraphDefs->{'temperature'}; } our $GraphArgs = @@ -872,7 +859,6 @@ our $GraphArgs = #disk => ['-t', '{host} disk {inst} IO wait', '-v', 'Seconds'], df => ['-t', '{host}:{inst} usage', '-v', 'Percent', '-l', '0'], disk => ['-t', '{host} disk {inst} usage', '-v', 'Byte/s'], - fanspeed => ['-t', '{host} fanspeed {inst}', '-v', 'rpm'], hddtemp => ['-t', '{host} hdd temperature {inst}', '-v', '°Celsius'], load => ['-t', '{host} load average', '-v', 'System load', '-X', '0'], mails => ['-t', '{host} mail count', '-v', 'Amount', '-X', '0'], @@ -887,7 +873,6 @@ our $GraphArgs = processes => ['-t', '{host} processes', '-v', 'Processes'], sensors => ['-t', '{host} sensor {inst}', '-v', '°Celsius'], swap => ['-t', '{host} swap usage', '-v', 'Bytes', '-b', '1024', '-l', '0'], - temperature => ['-t', '{host} temperature {inst}', '-v', '°Celsius'], traffic => ['-t', '{host} {inst} traffic', '-v', 'Bit/s'], users => ['-t', '{host} users', '-v', 'Users'], voltage => ['-t', '{host} voltage', '-v', 'Volts'], @@ -911,7 +896,7 @@ our $GraphMulti = ping => \&output_graph_ping, sensors => 1, traffic => 1, - users => 1 + users => 1 }; our @Info; @@ -1474,7 +1459,7 @@ sub parse_pathinfo $AbsDir = $Config->{'Directory'}; $RelDir = ''; - while (@info and -d $AbsDir . '/' . $info[0]) + while (@info and -d $AbsDir . '/' . $Info[0]) { my $new = shift (@info); next if ($new =~ m/^\./); diff --git a/src/Makefile.am b/src/Makefile.am index 025548a1..c554abe9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -105,9 +105,6 @@ if BUILD_MODULE_DISK pkglib_LTLIBRARIES += disk.la disk_la_SOURCES = disk.c disk_la_LDFLAGS = -module -avoid-version -if BUILD_WITH_LIBIOKIT -disk_la_LDFLAGS += -lIOKit -endif collectd_LDADD += "-dlopen" disk.la collectd_DEPENDENCIES += disk.la endif diff --git a/src/battery.c b/src/battery.c index 10e8c00d..fa93b1c6 100644 --- a/src/battery.c +++ b/src/battery.c @@ -53,7 +53,7 @@ # include #endif -#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H || KERNEL_LINUX +#if HAVE_IOKIT_PS_IOPOWERSOURCES_H || KERNEL_LINUX # define BATTERY_HAVE_READ 1 #else # define BATTERY_HAVE_READ 0 @@ -86,9 +86,9 @@ static char *ds_def_charge[] = }; static int ds_num_charge = 1; -#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H +#if HAVE_IOKIT_PS_IOPOWERSOURCES_H /* No global variables */ -/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */ +/* #endif HAVE_IOKIT_PS_IOPOWERSOURCES_H */ #elif KERNEL_LINUX static int battery_pmu_num = 0; @@ -97,9 +97,9 @@ static char *battery_pmu_file = "/proc/pmu/battery_%i"; static void battery_init (void) { -#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H +#if HAVE_IOKIT_PS_IOPOWERSOURCES_H /* No init neccessary */ -/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */ +/* #endif HAVE_IOKIT_PS_IOPOWERSOURCES_H */ #elif KERNEL_LINUX int len; @@ -202,68 +202,23 @@ static void battery_submit (char *inst, double current, double voltage, double c } } -double dict_get_double (CFDictionaryRef dict, char *key_string) +static void battery_read (void) { - double val_double; - long long val_int; - CFNumberRef val_obj; - CFStringRef key_obj; - - key_obj = CFStringCreateWithCString (kCFAllocatorDefault, key_string, - kCFStringEncodingASCII); - if (key_obj == NULL) - { - DBG ("CFStringCreateWithCString (%s) failed.\n", key_string); - return (INVALID_VALUE); - } - - if ((val_obj = CFDictionaryGetValue (dict, key_obj)) == NULL) - { - DBG ("CFDictionaryGetValue (%s) failed.", key_string); - CFRelease (key_obj); - return (INVALID_VALUE); - } - CFRelease (key_obj); - - if (CFGetTypeID (val_obj) == CFNumberGetTypeID ()) - { - if (CFNumberIsFloatType (val_obj)) - { - CFNumberGetValue (val_obj, - kCFNumberDoubleType, - &val_double); - } - else - { - CFNumberGetValue (val_obj, - kCFNumberLongLongType, - &val_int); - val_double = val_int; - } - } - else - { - DBG ("CFGetTypeID (val_obj) = %i", (int) CFGetTypeID (val_obj)); - return (INVALID_VALUE); - } - - return (val_double); -} - #if HAVE_IOKIT_PS_IOPOWERSOURCES_H -static void get_via_io_power_sources (double *ret_charge, - double *ret_current, - double *ret_voltage) -{ CFTypeRef ps_raw; CFArrayRef ps_array; int ps_array_len; CFDictionaryRef ps_dict; CFTypeRef ps_obj; + CFTypeRef ps_value; - double temp_double; int i; + char name[128]; + double charge = INVALID_VALUE; + double current = INVALID_VALUE; + double voltage = INVALID_VALUE; + ps_raw = IOPSCopyPowerSourcesInfo (); ps_array = IOPSCopyPowerSourcesList (ps_raw); ps_array_len = CFArrayGetCount (ps_array); @@ -275,163 +230,110 @@ static void get_via_io_power_sources (double *ret_charge, ps_obj = CFArrayGetValueAtIndex (ps_array, i); ps_dict = IOPSGetPowerSourceDescription (ps_raw, ps_obj); - if (ps_dict == NULL) - { - DBG ("IOPSGetPowerSourceDescription failed."); - continue; - } - if (CFGetTypeID (ps_dict) != CFDictionaryGetTypeID ()) { DBG ("IOPSGetPowerSourceDescription did not return a CFDictionaryRef"); continue; } - /* FIXME: Check if this is really an internal battery */ - - if (*ret_charge == INVALID_VALUE) - { - /* This is the charge in percent. */ - temp_double = dict_get_double (ps_dict, - kIOPSCurrentCapacityKey); - if ((temp_double != INVALID_VALUE) - && (temp_double >= 0.0) - && (temp_double <= 100.0)) - *ret_charge = temp_double; - } - - if (*ret_current == INVALID_VALUE) - { - temp_double = dict_get_double (ps_dict, - kIOPSCurrentKey); - if (temp_double != INVALID_VALUE) - *ret_current = temp_double / 1000.0; - } - - if (*ret_voltage == INVALID_VALUE) - { - temp_double = dict_get_double (ps_dict, - kIOPSVoltageKey); - if (temp_double != INVALID_VALUE) - *ret_voltage = temp_double / 1000.0; - } - } - - CFRelease(ps_array); - CFRelease(ps_raw); -} -#endif /* HAVE_IOKIT_PS_IOPOWERSOURCES_H */ - -#if HAVE_IOKIT_IOKITLIB_H -static void get_via_generic_iokit (double *ret_charge, - double *ret_current, - double *ret_voltage) -{ - kern_return_t status; - io_iterator_t iterator; - io_object_t io_obj; - - CFDictionaryRef bat_root_dict; - CFArrayRef bat_info_arry; - CFIndex bat_info_arry_len; - CFIndex bat_info_arry_pos; - CFDictionaryRef bat_info_dict; - - double temp_double; - - status = IOServiceGetMatchingServices (kIOMasterPortDefault, - IOServiceNameMatching ("battery"), - &iterator); - if (status != kIOReturnSuccess) - { - DBG ("IOServiceGetMatchingServices failed."); - return; - } - - while ((io_obj = IOIteratorNext (iterator))) - { - status = IORegistryEntryCreateCFProperties (io_obj, - (CFMutableDictionaryRef *) &bat_root_dict, - kCFAllocatorDefault, - kNilOptions); - if (status != kIOReturnSuccess) - { - DBG ("IORegistryEntryCreateCFProperties failed."); - continue; - } - - bat_info_arry = (CFArrayRef) CFDictionaryGetValue (bat_root_dict, - CFSTR ("IOBatteryInfo")); - if (bat_info_arry == NULL) - { - CFRelease (bat_root_dict); - continue; - } - bat_info_arry_len = CFArrayGetCount (bat_info_arry); - - for (bat_info_arry_pos = 0; - bat_info_arry_pos < bat_info_arry_len; - bat_info_arry_pos++) + if (ps_dict != NULL) { - bat_info_dict = (CFDictionaryRef) CFArrayGetValueAtIndex (bat_info_arry, bat_info_arry_pos); + /* Get the current capacity/charge */ + ps_value = NULL; + charge = INVALID_VALUE; + if (CFDictionaryGetValueIfPresent (ps_dict, + CFSTR (kIOPSCurrentCapacityKey), + &ps_value)) + { + if (CFGetTypeID (ps_value) != CFNumberGetTypeID ()) + CFNumberGetValue (ps_value, + kCFNumberDoubleType, + &charge); + else + DBG ("kIOPSCurrentCapacityKey: Not a CFNumber"); - if (*ret_charge == INVALID_VALUE) + DBG ("charge = %f", charge); + } + else + DBG ("`%s' does not exist", kIOPSCurrentCapacityKey); + + /* Get the current */ + ps_value = NULL; + current = INVALID_VALUE; + if (CFDictionaryGetValueIfPresent (ps_dict, + CFSTR (kIOPSCurrentKey), + &ps_value)) { - temp_double = dict_get_double (bat_info_dict, - "Capacity"); - if (temp_double != INVALID_VALUE) - *ret_charge = temp_double / 1000.0; + if (CFGetTypeID (ps_value) != CFNumberGetTypeID ()) + CFNumberGetValue (ps_value, + kCFNumberDoubleType, + ¤t); + else + DBG ("kIOPSCurrentKey: Not a CFNumber"); + DBG ("current = %f", current); } - - if (*ret_current == INVALID_VALUE) + else + DBG ("`%s' does not exist", kIOPSCurrentKey); + + /* Get the voltage */ + ps_value = NULL; + voltage = INVALID_VALUE; + if (CFDictionaryGetValueIfPresent (ps_dict, + CFSTR (kIOPSVoltageKey), + &ps_value)) { - temp_double = dict_get_double (bat_info_dict, - "Current"); - if (temp_double != INVALID_VALUE) - *ret_current = temp_double / 1000.0; + if (CFGetTypeID (ps_value) != CFNumberGetTypeID ()) + CFNumberGetValue (ps_value, + kCFNumberDoubleType, + &voltage); + else + DBG ("kIOPSVoltageKey: Not a CFNumber"); + DBG ("voltage = %f", voltage); } + else + DBG ("`%s' does not exist", kIOPSVoltageKey); - if (*ret_voltage == INVALID_VALUE) + /* Get the name of the device.. */ + ps_value = NULL; + if (CFDictionaryGetValueIfPresent (ps_dict, + CFSTR (kIOPSNameKey), + &ps_value)) + { + if (CFGetTypeID (ps_value) != CFStringGetTypeID ()) + { + if (!CFStringGetCString (ps_value, + name, 128, + kCFStringEncodingASCII)) + continue; + } + else + { + DBG ("kIOPSNameKey: Not a CFStringGetTypeID"); + } + DBG ("Original string: `%s'", name); + } + else + { + strncpy (name, "unknown", 128); + } + name[127] = '\0'; + for (i = 0; i < 128; i++) { - temp_double = dict_get_double (bat_info_dict, - "Voltage"); - if (temp_double != INVALID_VALUE) - *ret_voltage = temp_double / 1000.0; + if (name[i] == '\0') + break; + else if (isalnum (name[i])) + name[i] = (char) tolower (name[i]); + else + name[i] = '_'; } + + battery_submit (name, current, voltage, charge); } - - CFRelease (bat_root_dict); } - IOObjectRelease (iterator); -} -#endif /* HAVE_IOKIT_IOKITLIB_H */ - -static void battery_read (void) -{ -#if HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H - double charge = INVALID_VALUE; /* Current charge in Ah */ - double current = INVALID_VALUE; /* Current in A */ - double voltage = INVALID_VALUE; /* Voltage in V */ - - double charge_rel = INVALID_VALUE; /* Current charge in percent */ - double charge_abs = INVALID_VALUE; /* Total capacity */ - -#if HAVE_IOKIT_PS_IOPOWERSOURCES_H - get_via_io_power_sources (&charge_rel, ¤t, &voltage); -#endif -#if HAVE_IOKIT_IOKITLIB_H - get_via_generic_iokit (&charge_abs, ¤t, &voltage); -#endif - - if ((charge_rel != INVALID_VALUE) && (charge_abs != INVALID_VALUE)) - charge = charge_abs * charge_rel / 100.0; - - if ((charge != INVALID_VALUE) - || (current != INVALID_VALUE) - || (voltage != INVALID_VALUE)) - battery_submit ("0", current, voltage, charge); -/* #endif HAVE_IOKIT_IOKITLIB_H || HAVE_IOKIT_PS_IOPOWERSOURCES_H */ + CFRelease(ps_array); + CFRelease(ps_raw); +/* #endif HAVE_IOKIT_PS_IOPOWERSOURCES_H */ #elif KERNEL_LINUX FILE *fh; diff --git a/src/disk.c b/src/disk.c index 6aefbc7d..ded20806 100644 --- a/src/disk.c +++ b/src/disk.c @@ -23,39 +23,10 @@ #include "collectd.h" #include "common.h" #include "plugin.h" -#include "utils_debug.h" #define MODULE_NAME "disk" -#if HAVE_MACH_MACH_TYPES_H -# include -#endif -#if HAVE_MACH_MACH_INIT_H -# include -#endif -#if HAVE_MACH_MACH_ERROR_H -# include -#endif -#if HAVE_MACH_MACH_PORT_H -# include -#endif -#if HAVE_COREFOUNDATION_COREFOUNDATION_H -# include -#endif -#if HAVE_IOKIT_IOKITLIB_H -# include -#endif -#if HAVE_IOKIT_IOTYPES_H -# include -#endif -#if HAVE_IOKIT_STORAGE_IOBLOCKSTORAGEDRIVER_H -# include -#endif -#if HAVE_IOKIT_IOBSD_H -# include -#endif - -#if HAVE_IOKIT_IOKITLIB_H || KERNEL_LINUX || HAVE_LIBKSTAT +#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) # define DISK_HAVE_READ 1 #else # define DISK_HAVE_READ 0 @@ -89,11 +60,7 @@ static char *part_ds_def[] = }; static int part_ds_num = 4; -#if HAVE_IOKIT_IOKITLIB_H -static mach_port_t io_master_port = MACH_PORT_NULL; -/* #endif HAVE_IOKIT_IOKITLIB_H */ - -#elif KERNEL_LINUX +#ifdef KERNEL_LINUX typedef struct diskstats { char *name; @@ -111,9 +78,9 @@ typedef struct diskstats } diskstats_t; static diskstats_t *disklist; -/* #endif KERNEL_LINUX */ +/* #endif defined(KERNEL_LINUX) */ -#elif HAVE_LIBKSTAT +#elif defined(HAVE_LIBKSTAT) #define MAX_NUMDISK 256 extern kstat_ctl_t *kc; static kstat_t *ksp[MAX_NUMDISK]; @@ -122,31 +89,7 @@ static int numdisk = 0; static void disk_init (void) { -#if HAVE_IOKIT_IOKITLIB_H - kern_return_t status; - - if (io_master_port != MACH_PORT_NULL) - { - mach_port_deallocate (mach_task_self (), - io_master_port); - io_master_port = MACH_PORT_NULL; - } - - status = IOMasterPort (MACH_PORT_NULL, &io_master_port); - if (status != kIOReturnSuccess) - { - syslog (LOG_ERR, "IOMasterPort failed: %s", - mach_error_string (status)); - io_master_port = MACH_PORT_NULL; - return; - } -/* #endif HAVE_IOKIT_IOKITLIB_H */ - -#elif KERNEL_LINUX - /* No init needed */ -/* #endif KERNEL_LINUX */ - -#elif HAVE_LIBKSTAT +#ifdef HAVE_LIBKSTAT kstat_t *ksp_chain; numdisk = 0; @@ -165,7 +108,7 @@ static void disk_init (void) continue; ksp[numdisk++] = ksp_chain; } -#endif /* HAVE_LIBKSTAT */ +#endif return; } @@ -222,7 +165,6 @@ static void disk_submit (char *disk_name, plugin_submit (MODULE_NAME, disk_name, buf); } -#if KERNEL_LINUX || HAVE_LIBKSTAT static void partition_submit (char *part_name, unsigned long long read_count, unsigned long long read_bytes, @@ -239,187 +181,11 @@ static void partition_submit (char *part_name, plugin_submit ("partition", part_name, buf); } -#endif /* KERNEL_LINUX || HAVE_LIBKSTAT */ #undef BUFSIZE -#if HAVE_IOKIT_IOKITLIB_H -static signed long long dict_get_value (CFDictionaryRef dict, const char *key) -{ - signed long long val_int; - CFNumberRef val_obj; - CFStringRef key_obj; - - /* `key_obj' needs to be released. */ - key_obj = CFStringCreateWithCString (kCFAllocatorDefault, key, - kCFStringEncodingASCII); - if (key_obj == NULL) - { - DBG ("CFStringCreateWithCString (%s) failed.", key); - return (-1LL); - } - - /* get => we don't need to release (== free) the object */ - val_obj = (CFNumberRef) CFDictionaryGetValue (dict, key_obj); - - CFRelease (key_obj); - - if (val_obj == NULL) - { - DBG ("CFDictionaryGetValue (%s) failed.", key); - return (-1LL); - } - - if (!CFNumberGetValue (val_obj, kCFNumberSInt64Type, &val_int)) - { - DBG ("CFNumberGetValue (%s) failed.", key); - return (-1LL); - } - - return (val_int); -} -#endif /* HAVE_IOKIT_IOKITLIB_H */ - static void disk_read (void) { -#if HAVE_IOKIT_IOKITLIB_H - io_registry_entry_t disk; - io_registry_entry_t disk_child; - io_iterator_t disk_list; - CFDictionaryRef props_dict; - CFDictionaryRef stats_dict; - CFDictionaryRef child_dict; - kern_return_t status; - - signed long long read_ops; - signed long long read_byt; - signed long long read_tme; - signed long long write_ops; - signed long long write_byt; - signed long long write_tme; - - int disk_major; - int disk_minor; - char disk_name[64]; - - /* Get the list of all disk objects. */ - if (IOServiceGetMatchingServices (io_master_port, - IOServiceMatching (kIOBlockStorageDriverClass), - &disk_list) != kIOReturnSuccess) - { - syslog (LOG_ERR, "disk-plugin: IOServiceGetMatchingServices failed."); - return; - } - - while ((disk = IOIteratorNext (disk_list)) != 0) - { - props_dict = NULL; - stats_dict = NULL; - child_dict = NULL; - - /* `disk_child' must be released */ - if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) - != kIOReturnSuccess) - { - /* This fails for example for DVD/CD drives.. */ - DBG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status); - IOObjectRelease (disk); - continue; - } - - /* We create `props_dict' => we need to release it later */ - if (IORegistryEntryCreateCFProperties (disk, - (CFMutableDictionaryRef *) &props_dict, - kCFAllocatorDefault, - kNilOptions) - != kIOReturnSuccess) - { - syslog (LOG_ERR, "disk-plugin: IORegistryEntryCreateCFProperties failed."); - IOObjectRelease (disk_child); - IOObjectRelease (disk); - continue; - } - - if (props_dict == NULL) - { - DBG ("IORegistryEntryCreateCFProperties (disk) failed."); - IOObjectRelease (disk_child); - IOObjectRelease (disk); - continue; - } - - stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, - CFSTR (kIOBlockStorageDriverStatisticsKey)); - - if (stats_dict == NULL) - { - DBG ("CFDictionaryGetValue (%s) failed.", - kIOBlockStorageDriverStatisticsKey); - CFRelease (props_dict); - IOObjectRelease (disk_child); - IOObjectRelease (disk); - continue; - } - - if (IORegistryEntryCreateCFProperties (disk_child, - (CFMutableDictionaryRef *) &child_dict, - kCFAllocatorDefault, - kNilOptions) - != kIOReturnSuccess) - { - DBG ("IORegistryEntryCreateCFProperties (disk_child) failed."); - IOObjectRelease (disk_child); - CFRelease (props_dict); - IOObjectRelease (disk); - continue; - } - - disk_major = (int) dict_get_value (child_dict, - kIOBSDMajorKey); - disk_minor = (int) dict_get_value (child_dict, - kIOBSDMinorKey); - read_ops = dict_get_value (stats_dict, - kIOBlockStorageDriverStatisticsReadsKey); - read_byt = dict_get_value (stats_dict, - kIOBlockStorageDriverStatisticsBytesReadKey); - read_tme = dict_get_value (stats_dict, - kIOBlockStorageDriverStatisticsTotalReadTimeKey); - write_ops = dict_get_value (stats_dict, - kIOBlockStorageDriverStatisticsWritesKey); - write_byt = dict_get_value (stats_dict, - kIOBlockStorageDriverStatisticsBytesWrittenKey); - write_tme = dict_get_value (stats_dict, - kIOBlockStorageDriverStatisticsTotalWriteTimeKey); - - if (snprintf (disk_name, 64, "%i-%i", disk_major, disk_minor) >= 64) - { - DBG ("snprintf (major, minor) failed."); - CFRelease (child_dict); - IOObjectRelease (disk_child); - CFRelease (props_dict); - IOObjectRelease (disk); - continue; - } - DBG ("disk_name = %s", disk_name); - - if ((read_ops != -1LL) - || (read_byt != -1LL) - || (read_tme != -1LL) - || (write_ops != -1LL) - || (write_byt != -1LL) - || (write_tme != -1LL)) - disk_submit (disk_name, - read_ops, 0ULL, read_byt, read_tme, - write_ops, 0ULL, write_byt, write_tme); - - CFRelease (child_dict); - IOObjectRelease (disk_child); - CFRelease (props_dict); - IOObjectRelease (disk); - } - IOObjectRelease (disk_list); -/* #endif HAVE_IOKIT_IOKITLIB_H */ - -#elif KERNEL_LINUX +#ifdef KERNEL_LINUX FILE *fh; char buffer[1024]; char disk_name[128]; @@ -555,7 +321,7 @@ static void disk_read (void) fclose (fh); /* #endif defined(KERNEL_LINUX) */ -#elif HAVE_LIBKSTAT +#elif defined(HAVE_LIBKSTAT) static kstat_io_t kio; int i; diff --git a/src/liboping/liboping.c b/src/liboping/liboping.c index 57de9b5f..43d5fd50 100644 --- a/src/liboping/liboping.c +++ b/src/liboping/liboping.c @@ -87,46 +87,11 @@ # define dprintf(...) /**/ #endif -#define PING_ERRMSG_LEN 256 - #define PING_DATA "Florian Forster http://verplant.org/" -struct pinghost -{ - char *hostname; - struct sockaddr_storage *addr; - socklen_t addrlen; - int addrfamily; - int fd; - int ident; - int sequence; - struct timeval *timer; - double latency; - - struct pinghost *next; -}; - -struct pingobj -{ - double timeout; - int ttl; - int addrfamily; - - char errmsg[PING_ERRMSG_LEN]; - - pinghost_t *head; -}; - /* * private (static) functions */ -static void ping_set_error (pingobj_t *obj, const char *function, - const char *message) -{ - snprintf (obj->errmsg, PING_ERRMSG_LEN, "%s: %s", function, message); - obj->errmsg[PING_ERRMSG_LEN - 1] = '\0'; -} - static int ping_timeval_add (struct timeval *tv1, struct timeval *tv2, struct timeval *res) { @@ -423,10 +388,7 @@ static int ping_receive_all (pingobj_t *obj) ptr->latency = -1.0; if (gettimeofday (&nowtime, NULL) == -1) - { - ping_set_error (obj, "gettimeofday", strerror (errno)); return (-1); - } /* Set up timeout */ timeout.tv_sec = (time_t) obj->timeout; @@ -460,10 +422,7 @@ static int ping_receive_all (pingobj_t *obj) break; if (gettimeofday (&nowtime, NULL) == -1) - { - ping_set_error (obj, "gettimeofday", strerror (errno)); return (-1); - } if (ping_timeval_sub (&endtime, &nowtime, &timeout) == -1) break; @@ -475,10 +434,7 @@ static int ping_receive_all (pingobj_t *obj) status = select (max_readfds + 1, &readfds, NULL, NULL, &timeout); if (gettimeofday (&nowtime, NULL) == -1) - { - ping_set_error (obj, "gettimeofday", strerror (errno)); return (-1); - } if ((status == -1) && (errno == EINTR)) { @@ -514,7 +470,7 @@ static int ping_receive_all (pingobj_t *obj) * +-> ping_send_one_ipv4 * * `-> ping_send_one_ipv6 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -static ssize_t ping_sendto (pinghost_t *ph, const void *buf, size_t buflen) +ssize_t ping_sendto (pinghost_t *ph, const void *buf, size_t buflen) { ssize_t ret; @@ -758,18 +714,14 @@ static void ping_free (pinghost_t *ph) /* * public methods */ -const char *ping_get_error (pingobj_t *obj) -{ - return (obj->errmsg); -} - pingobj_t *ping_construct (void) { pingobj_t *obj; if ((obj = (pingobj_t *) malloc (sizeof (pingobj_t))) == NULL) return (NULL); - memset (obj, '\0', sizeof (pingobj_t)); + + obj->head = NULL; return (obj); } @@ -896,7 +848,6 @@ int ping_host_add (pingobj_t *obj, const char *host) if ((ph->hostname = strdup (host)) == NULL) { dprintf ("Out of memory!\n"); - ping_set_error (obj, "strdup", strerror (errno)); ping_free (ph); return (-1); } @@ -904,17 +855,10 @@ int ping_host_add (pingobj_t *obj, const char *host) if ((ai_return = getaddrinfo (host, NULL, &ai_hints, &ai_list)) != 0) { dprintf ("getaddrinfo failed\n"); - ping_set_error (obj, "getaddrinfo", - (ai_return == EAI_SYSTEM) - ? strerror (errno) - : gai_strerror (ai_return)); ping_free (ph); return (-1); } - if (ai_list == NULL) - ping_set_error (obj, "getaddrinfo", "No hosts returned"); - for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { ph->fd = -1; @@ -931,7 +875,6 @@ int ping_host_add (pingobj_t *obj, const char *host) si->sin_port = htons (ph->ident); si->sin_addr.s_addr = htonl (INADDR_ANY); - ai_ptr->ai_socktype = SOCK_RAW; ai_ptr->ai_protocol = IPPROTO_ICMP; } else if (ai_ptr->ai_family == AF_INET6) @@ -943,18 +886,11 @@ int ping_host_add (pingobj_t *obj, const char *host) si->sin6_port = htons (ph->ident); si->sin6_addr = in6addr_any; - ai_ptr->ai_socktype = SOCK_RAW; ai_ptr->ai_protocol = IPPROTO_ICMPV6; } else { - char errmsg[PING_ERRMSG_LEN]; - - snprintf (errmsg, PING_ERRMSG_LEN, "Unknown `ai_family': %i", ai_ptr->ai_family); - errmsg[PING_ERRMSG_LEN - 1] = '\0'; - - dprintf (errmsg); - ping_set_error (obj, "getaddrinfo", errmsg); + dprintf ("Unknown `ai_family': %i\n", ai_ptr->ai_family); continue; } @@ -962,14 +898,12 @@ int ping_host_add (pingobj_t *obj, const char *host) if (ph->fd == -1) { dprintf ("socket: %s\n", strerror (errno)); - ping_set_error (obj, "socket", strerror (errno)); continue; } if (bind (ph->fd, (struct sockaddr *) &sockaddr, sockaddr_len) == -1) { dprintf ("bind: %s\n", strerror (errno)); - ping_set_error (obj, "bind", strerror (errno)); close (ph->fd); ph->fd = -1; continue; @@ -1018,10 +952,7 @@ int ping_host_remove (pingobj_t *obj, const char *host) } if (cur == NULL) - { - ping_set_error (obj, "ping_host_remove", "Host not found"); return (-1); - } if (pre == NULL) obj->head = cur->next; diff --git a/src/liboping/liboping.h b/src/liboping/liboping.h index 9fd7597f..065ae950 100644 --- a/src/liboping/liboping.h +++ b/src/liboping/liboping.h @@ -37,13 +37,31 @@ /* * Type definitions */ -struct pinghost; -typedef struct pinghost pinghost_t; +typedef struct pinghost +{ + char *hostname; + struct sockaddr_storage *addr; + socklen_t addrlen; + int addrfamily; + int fd; + int ident; + int sequence; + struct timeval *timer; + double latency; + + struct pinghost *next; +} pinghost_t; typedef pinghost_t pingobj_iter_t; -struct pingobj; -typedef struct pingobj pingobj_t; +typedef struct pingobj +{ + double timeout; + int ttl; + int addrfamily; + + pinghost_t *head; +} pingobj_t; #define PING_OPT_TIMEOUT 0x01 #define PING_OPT_TTL 0x02 @@ -72,6 +90,4 @@ pingobj_iter_t *ping_iterator_next (pingobj_iter_t *iter); const char *ping_iterator_get_host (pingobj_iter_t *iter); double ping_iterator_get_latency (pingobj_iter_t *iter); -const char *ping_get_error (pingobj_t *obj); - #endif /* OCTO_PING_H */ diff --git a/src/ping.c b/src/ping.c index 91e0dbcc..d82ce06e 100644 --- a/src/ping.c +++ b/src/ping.c @@ -61,8 +61,7 @@ static int ping_config (char *key, char *value) { if ((pingobj = ping_construct ()) == NULL) { - syslog (LOG_ERR, "ping: `ping_construct' failed: %s", - ping_get_error (pingobj)); + syslog (LOG_ERR, "ping: `ping_construct' failed.\n"); return (1); } } @@ -71,8 +70,7 @@ static int ping_config (char *key, char *value) { if (ping_host_add (pingobj, value) < 0) { - syslog (LOG_WARNING, "ping: `ping_host_add' failed: %s", - ping_get_error (pingobj)); + syslog (LOG_WARNING, "ping: `ping_host_add' failed."); return (1); } } @@ -131,8 +129,7 @@ static void ping_read (void) if (ping_send (pingobj) < 0) { - syslog (LOG_ERR, "ping: `ping_send' failed: %s", - ping_get_error (pingobj)); + syslog (LOG_ERR, "ping: `ping_send' failed."); return; } -- 2.11.0