X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcpu.c;h=9c432d1791d0090191842aa364c48d761b5da72e;hb=3dc0454f7bee3e852171d1f6944891693364ee01;hp=bcaea38c546305968487a8c509e117b09dfa1e0a;hpb=71478cd6550a4e930a1e9b8a906a66579e4e387a;p=collectd.git diff --git a/src/cpu.c b/src/cpu.c index bcaea38c..9c432d17 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 */ @@ -804,8 +814,7 @@ static int cpu_read (void) if (pnumcpu != numcpu || perfcpu == NULL) { - if (perfcpu != NULL) - free(perfcpu); + free(perfcpu); perfcpu = malloc(numcpu * sizeof(perfstat_cpu_t)); } pnumcpu = numcpu;