here comes the big header include rewrite
[monky] / src / linux.c
index a48e983..57b6f59 100644 (file)
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
- * $Id$ */
+ */
 
 #include "conky.h"
+#include "logging.h"
+#include "common.h"
+#include "linux.h"
 #include <dirent.h>
 #include <ctype.h>
 #include <errno.h>
@@ -676,7 +679,7 @@ inline static void update_stat(void)
                } else if (strncmp(buf, "cpu", 3) == 0) {
                        double delta;
                        if (isdigit(buf[3])) {
-                               idx = atoi(&buf[3]);
+                               idx = atoi(&buf[3]) + 1;
                        } else {
                                idx = 0;
                        }
@@ -2337,7 +2340,10 @@ const char *get_disk_protect_queue(const char *disk)
        char path[128];
        int state;
 
-       snprintf(path, 127, "/sys/block/%s/queue/protect", disk);
+       snprintf(path, 127, "/sys/block/%s/device/unload_heads", disk);
+       if (access(path, F_OK)) {
+               snprintf(path, 127, "/sys/block/%s/queue/protect", disk);
+       }
        if ((fp = fopen(path, "r")) == NULL)
                return "n/a   ";
        if (fscanf(fp, "%d\n", &state) != 1) {
@@ -2345,6 +2351,6 @@ const char *get_disk_protect_queue(const char *disk)
                return "failed";
        }
        fclose(fp);
-       return state ? "frozen" : "free  ";
+       return (state > 0) ? "frozen" : "free  ";
 }