diff --git a/src/conky.c b/src/conky.c index 1b42918b..8c07e507 100644 --- a/src/conky.c +++ b/src/conky.c @@ -897,11 +897,6 @@ void generate_text_internal(char *p, int p_max_size, } #endif /* X11 */ #if defined(__linux__) - OBJ(disk_protect) { - snprintf(p, p_max_size, "%s", - get_disk_protect_queue(obj->data.s)); - } - } OBJ(if_gw) { if (!gateway_exists()) { DO_JUMP; diff --git a/src/core.c b/src/core.c index 4674164d..57094ab0 100644 --- a/src/core.c +++ b/src/core.c @@ -295,6 +295,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #if defined(__linux__) END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument") obj->data.s = strndup(dev_name(arg), text_buffer_size); + obj->callbacks.print = &print_disk_protect_queue; obj->callbacks.free = &gen_free_opaque; END OBJ(i8k_version, &update_i8k) obj->callbacks.print = &print_i8k_version; diff --git a/src/linux.c b/src/linux.c index d63dc993..b9333817 100644 --- a/src/linux.c +++ b/src/linux.c @@ -2229,24 +2229,27 @@ int get_entropy_poolsize(unsigned int *val) return 0; } -const char *get_disk_protect_queue(const char *disk) +void print_disk_protect_queue(struct text_object *obj, char *p, int p_max_size) { FILE *fp; char path[128]; int state; - snprintf(path, 127, "/sys/block/%s/device/unload_heads", disk); + snprintf(path, 127, "/sys/block/%s/device/unload_heads", obj->data.s); if (access(path, F_OK)) { - snprintf(path, 127, "/sys/block/%s/queue/protect", disk); + snprintf(path, 127, "/sys/block/%s/queue/protect", obj->data.s); + } + if ((fp = fopen(path, "r")) == NULL) { + snprintf(p, p_max_size, "n/a "); + return; } - if ((fp = fopen(path, "r")) == NULL) - return "n/a "; if (fscanf(fp, "%d\n", &state) != 1) { fclose(fp); - return "failed"; + snprintf(p, p_max_size, "failed"); + return; } fclose(fp); - return (state > 0) ? "frozen" : "free "; + snprintf(p, p_max_size, (state > 0) ? "frozen" : "free "); } void update_diskio(void) diff --git a/src/linux.h b/src/linux.h index 10eb46e2..ded56b6c 100644 --- a/src/linux.h +++ b/src/linux.h @@ -5,7 +5,7 @@ #include "common.h" -const char *get_disk_protect_queue(const char *); +void print_disk_protect_queue(struct text_object *, char *, int); char *get_ioscheduler(char *); void print_laptop_mode(struct text_object *, char *, int);