X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcpu.c;h=7f8c9858995c7d11f3d853905e4d3e574d660822;hb=5c2993e4121feae745551be182221b31bc23ff97;hp=2a2a4a9715d20e9b76055d559edcb1b2f9e55aa1;hpb=d6491cfcf52a74498e1becd7ef94fc8e0a5938b9;p=collectd.git diff --git a/src/cpu.c b/src/cpu.c index 2a2a4a97..7f8c9858 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -221,15 +221,25 @@ static int init (void) port_host = mach_host_self (); - /* FIXME: Free `cpu_list' if it's not NULL */ - if ((status = host_processors (port_host, &cpu_list, &cpu_list_len)) != KERN_SUCCESS) + status = host_processors (port_host, &cpu_list, &cpu_list_len); + if (status == KERN_INVALID_ARGUMENT) { - ERROR ("cpu plugin: host_processors returned %i", (int) status); + ERROR ("cpu plugin: Don't have a privileged host control port. " + "The most common cause for this problem is " + "that collectd is running without root " + "privileges, which are required to read CPU " + "load information. " + ""); + cpu_list_len = 0; + return (-1); + } + if (status != KERN_SUCCESS) + { + ERROR ("cpu plugin: host_processors() failed with status %d.", (int) status); cpu_list_len = 0; return (-1); } - DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors"); INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s"); /* #endif PROCESSOR_CPU_LOAD_INFO */ @@ -526,11 +536,12 @@ static void cpu_commit (void) /* {{{ */ /* Adds a derive value to the internal state. This should be used by each read * function for each state. At the end of the iteration, the read function * should call cpu_commit(). */ -static int cpu_stage (size_t cpu_num, size_t state, derive_t value, cdtime_t now) /* {{{ */ +static int cpu_stage (size_t cpu_num, size_t state, derive_t d, cdtime_t now) /* {{{ */ { int status; cpu_state_t *s; - value_t v; + gauge_t rate = NAN; + value_t val = {.derive = d}; if (state >= COLLECTD_CPU_STATE_ACTIVE) return (EINVAL); @@ -544,12 +555,11 @@ static int cpu_stage (size_t cpu_num, size_t state, derive_t value, cdtime_t now s = get_cpu_state (cpu_num, state); - v.gauge = NAN; - status = value_to_rate (&v, value, &s->conv, DS_TYPE_DERIVE, now); + status = value_to_rate (&rate, val, DS_TYPE_DERIVE, now, &s->conv); if (status != 0) return (status); - s->rate = v.gauge; + s->rate = rate; s->has_value = 1; return (0); } /* }}} int cpu_stage */