X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fapple_sensors.c;h=37bd5c3965284f9e32ce39dc3cedda131d3f60c4;hb=ec6fec62b15992b22774233c6a915e46673b25af;hp=a8f92a548654aa110d25c6b0852f576adde8179c;hpb=3db1540066e3fcbfe3735b902131b5c5eb073de0;p=collectd.git diff --git a/src/apple_sensors.c b/src/apple_sensors.c index a8f92a54..37bd5c39 100644 --- a/src/apple_sensors.c +++ b/src/apple_sensors.c @@ -30,6 +30,7 @@ #if HAVE_CTYPE_H # include #endif + #if HAVE_MACH_MACH_TYPES_H # include #endif @@ -39,6 +40,9 @@ #if HAVE_MACH_MACH_ERROR_H # include #endif +#if HAVE_MACH_MACH_PORT_H +# include +#endif #if HAVE_COREFOUNDATION_COREFOUNDATION_H # include #endif @@ -55,8 +59,8 @@ # define IOKIT_HAVE_READ 0 #endif -#if IOKIT_HAVE_READ -static mach_port_t io_master_port; +#if HAVE_IOKIT_IOKITLIB_H +static mach_port_t io_master_port = MACH_PORT_NULL; #endif static char *temperature_file = "apple_sensors/temperature-%s.rrd"; @@ -74,7 +78,12 @@ static void as_init (void) #if IOKIT_HAVE_READ kern_return_t status; - /* FIXME: de-allocate port if it's defined */ + 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) @@ -84,7 +93,7 @@ static void as_init (void) io_master_port = MACH_PORT_NULL; return; } -#endif +#endif /* IOKIT_HAVE_READ */ return; } @@ -215,11 +224,17 @@ static void as_read (void) &value_int)) continue; + /* Found e.g. in the 1.5GHz PowerBooks */ if (strcmp (type, "temperature") == 0) { value_double = ((double) value_int) / 65536.0; strncpy (type, "apple_temperature", 128); } + else if (strcmp (type, "temp") == 0) + { + value_double = ((double) value_int) / 10.0; + strncpy (type, "apple_temperature", 128); + } else if (strcmp (type, "fanspeed") == 0) { value_double = ((double) value_int) / 65536.0; @@ -230,6 +245,11 @@ static void as_read (void) /* Leave this to the battery plugin. */ continue; } + else if (strcmp (type, "adc") == 0) + { + value_double = ((double) value_int) / 10.0; + strncpy (type, "apple_temperature", 128); + } else { DBG ("apple_sensors: Read unknown sensor type: %s",