mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 04:17:33 +00:00
ioscheduler: convert to callbacks.print
This commit is contained in:
parent
712caa8ab3
commit
1832cf79c9
@ -998,11 +998,6 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
DO_JUMP;
|
DO_JUMP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if defined(__linux__)
|
|
||||||
OBJ(ioscheduler) {
|
|
||||||
snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
OBJ(kernel) {
|
OBJ(kernel) {
|
||||||
snprintf(p, p_max_size, "%s", cur->uname_s.release);
|
snprintf(p, p_max_size, "%s", cur->uname_s.release);
|
||||||
}
|
}
|
||||||
|
@ -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_IF(if_gw, &update_gateway_info)
|
||||||
END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
|
END OBJ_ARG(ioscheduler, 0, "get_ioscheduler needs an argument (e.g. hda)")
|
||||||
obj->data.s = strndup(dev_name(arg), text_buffer_size);
|
obj->data.s = strndup(dev_name(arg), text_buffer_size);
|
||||||
|
obj->callbacks.print = &print_ioscheduler;
|
||||||
obj->callbacks.free = &gen_free_opaque;
|
obj->callbacks.free = &gen_free_opaque;
|
||||||
END OBJ(laptop_mode, 0)
|
END OBJ(laptop_mode, 0)
|
||||||
obj->callbacks.print = &print_laptop_mode;
|
obj->callbacks.print = &print_laptop_mode;
|
||||||
|
21
src/linux.c
21
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
|
* # cat /sys/block/sda/queue/scheduler
|
||||||
* noop [anticipatory] cfq
|
* noop [anticipatory] cfq
|
||||||
*/
|
*/
|
||||||
char *get_ioscheduler(char *disk)
|
void print_ioscheduler(struct text_object *obj, char *p, int p_max_size)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
if (!disk)
|
if (!obj->data.s)
|
||||||
return strndup("n/a", text_buffer_size);
|
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)) {
|
while (!feof(fp)) {
|
||||||
fscanf(fp, "%127s", buf);
|
fscanf(fp, "%127s", buf);
|
||||||
if (buf[0] == '[') {
|
if (buf[0] == '[') {
|
||||||
buf[strlen(buf) - 1] = '\0';
|
buf[strlen(buf) - 1] = '\0';
|
||||||
|
snprintf(p, p_max_size, "%s", buf + 1);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return strndup(buf + 1, text_buffer_size);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return strndup("n/a", text_buffer_size);
|
out_fail:
|
||||||
|
snprintf(p, p_max_size, "n/a");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
void print_disk_protect_queue(struct text_object *, char *, int);
|
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 print_laptop_mode(struct text_object *, char *, int);
|
||||||
|
|
||||||
void update_gateway_info(void);
|
void update_gateway_info(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user