From: Vincent Brillault Date: Wed, 11 Feb 2015 22:00:05 +0000 (+0100) Subject: Turbostat: re-order init tests X-Git-Tag: collectd-5.5.0~24^2~25 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bb1b94f90e492d25aebe88949075c629fc7fe03d;p=collectd.git Turbostat: re-order init tests Calling 'stat' on /dev/cpu/0/msr does not need any specific permission and needs to be checked before probe_cpu. --- diff --git a/src/turbostat.c b/src/turbostat.c index 2d124fdc..34c11b88 100644 --- a/src/turbostat.c +++ b/src/turbostat.c @@ -1490,6 +1490,14 @@ turbostat_init(void) struct stat sb; int ret; + if (stat("/dev/cpu/0/msr", &sb)) { + ERROR("Turbostat plugin: Initialization failed: /dev/cpu/0/msr" + " does not exist while the CPU supports MSR. You may be " + "missing the corresponding kernel module, please try '# " + "modprobe msr'"); + return -1; + } + if (getuid() != 0) { ERROR("Turbostat plugin: Initialization failed: this plugin " "requires collectd to run as root in order to read " @@ -1499,14 +1507,6 @@ turbostat_init(void) DO_OR_GOTO_ERR(probe_cpu()); - if (stat("/dev/cpu/0/msr", &sb)) { - ERROR("Turbostat plugin: Initialization failed: /dev/cpu/0/msr" - " does not exist while the CPU supports MSR. You may be " - "missing the corresponding kernel module, please try '# " - "modprobe msr'"); - return -1; - } - DO_OR_GOTO_ERR(setup_all_buffers()); plugin_register_read(PLUGIN_NAME, turbostat_read);