1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-09-30 05:59:07 +00:00

convert disk_protect to callbacks.print

This commit is contained in:
Phil Sutter 2009-11-16 01:31:55 +01:00
parent 2660cb7590
commit a249b9bc44
4 changed files with 12 additions and 13 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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);