diff --git a/src/conky.c b/src/conky.c index 7366281d..be09b0dd 100644 --- a/src/conky.c +++ b/src/conky.c @@ -998,11 +998,6 @@ void generate_text_internal(char *p, int p_max_size, DO_JUMP; } } -#if defined(__linux__) - OBJ(ioscheduler) { - snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s)); - } -#endif OBJ(kernel) { snprintf(p, p_max_size, "%s", cur->uname_s.release); } diff --git a/src/core.c b/src/core.c index 7b2957ac..7486e68a 100644 --- a/src/core.c +++ b/src/core.c @@ -335,6 +335,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ_IF(if_gw, &update_gateway_info) END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)") obj->data.s = strndup(dev_name(arg), text_buffer_size); + obj->callbacks.print = &print_ioscheduler; obj->callbacks.free = &gen_free_opaque; END OBJ(laptop_mode, 0) obj->callbacks.print = &print_laptop_mode; diff --git a/src/linux.c b/src/linux.c index b9333817..ca82c36c 100644 --- a/src/linux.c +++ b/src/linux.c @@ -214,28 +214,31 @@ void print_laptop_mode(struct text_object *obj, char *p, int p_max_size) * # cat /sys/block/sda/queue/scheduler * noop [anticipatory] cfq */ -char *get_ioscheduler(char *disk) +void print_ioscheduler(struct text_object *obj, char *p, int p_max_size) { FILE *fp; char buf[128]; - if (!disk) - return strndup("n/a", text_buffer_size); + if (!obj->data.s) + goto out_fail; + + snprintf(buf, 127, "/sys/block/%s/queue/scheduler", obj->data.s); + if ((fp = fopen(buf, "r")) == NULL) + goto out_fail; - snprintf(buf, 127, "/sys/block/%s/queue/scheduler", disk); - if ((fp = fopen(buf, "r")) == NULL) { - return strndup("n/a", text_buffer_size); - } while (!feof(fp)) { fscanf(fp, "%127s", buf); if (buf[0] == '[') { buf[strlen(buf) - 1] = '\0'; + snprintf(p, p_max_size, "%s", buf + 1); fclose(fp); - return strndup(buf + 1, text_buffer_size); + return; } } fclose(fp); - return strndup("n/a", text_buffer_size); +out_fail: + snprintf(p, p_max_size, "n/a"); + return; } static struct { diff --git a/src/linux.h b/src/linux.h index ded56b6c..6d64b80a 100644 --- a/src/linux.h +++ b/src/linux.h @@ -7,7 +7,7 @@ void print_disk_protect_queue(struct text_object *, char *, int); -char *get_ioscheduler(char *); +void print_ioscheduler(struct text_object *, char *, int); void print_laptop_mode(struct text_object *, char *, int); void update_gateway_info(void);