Code

Turbostat: re-order init tests
authorVincent Brillault <git@lerya.net>
Wed, 11 Feb 2015 22:00:05 +0000 (23:00 +0100)
committerVincent Brillault <git@lerya.net>
Sat, 28 Feb 2015 06:35:42 +0000 (07:35 +0100)
Calling 'stat' on /dev/cpu/0/msr does not need any specific permission
and needs to be checked before probe_cpu.

src/turbostat.c

index 2d124fdc972df969b30ca5c313e6f3f102c7e572..34c11b889f619450c73e8ac97cca96743eec3256 100644 (file)
@@ -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);