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;
|
||||
}
|
||||
}
|
||||
#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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
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
|
||||
* 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 {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user