X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcpu.c;h=461a6e1bca64e653be62122cfb7c459b5a54228e;hb=f8379dd45f4a43595f4027992696ee8d02908bff;hp=6753397c0ca121fdf62c08b37859c0ca71cb6492;hpb=82e27678f8972d2625b466e7e7ba9daaa6395c98;p=collectd.git diff --git a/src/cpu.c b/src/cpu.c index 6753397c..461a6e1b 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -146,15 +146,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 */ @@ -258,7 +268,7 @@ static int cpu_read (void) int cpu; kern_return_t status; - + processor_cpu_load_info_data_t cpu_info; mach_msg_type_number_t cpu_info_len; @@ -512,10 +522,10 @@ static int cpu_read (void) sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } - - if (pnumcpu != numcpu || perfcpu == NULL) + + if (pnumcpu != numcpu || perfcpu == NULL) { - if (perfcpu != NULL) + if (perfcpu != NULL) free(perfcpu); perfcpu = malloc(numcpu * sizeof(perfstat_cpu_t)); } @@ -530,7 +540,7 @@ static int cpu_read (void) return (-1); } - for (i = 0; i < cpus; i++) + for (i = 0; i < cpus; i++) { submit (i, "idle", (derive_t) perfcpu[i].idle); submit (i, "system", (derive_t) perfcpu[i].sys);