mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-02-10 16:08:31 +00:00
convert disk_protect to callbacks.print
This commit is contained in:
parent
2660cb7590
commit
a249b9bc44
@ -897,11 +897,6 @@ void generate_text_internal(char *p, int p_max_size,
|
|||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
OBJ(disk_protect) {
|
|
||||||
snprintf(p, p_max_size, "%s",
|
|
||||||
get_disk_protect_queue(obj->data.s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
OBJ(if_gw) {
|
OBJ(if_gw) {
|
||||||
if (!gateway_exists()) {
|
if (!gateway_exists()) {
|
||||||
DO_JUMP;
|
DO_JUMP;
|
||||||
|
@ -295,6 +295,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
|
|||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument")
|
END OBJ_ARG(disk_protect, 0, "disk_protect needs an argument")
|
||||||
obj->data.s = strndup(dev_name(arg), text_buffer_size);
|
obj->data.s = strndup(dev_name(arg), text_buffer_size);
|
||||||
|
obj->callbacks.print = &print_disk_protect_queue;
|
||||||
obj->callbacks.free = &gen_free_opaque;
|
obj->callbacks.free = &gen_free_opaque;
|
||||||
END OBJ(i8k_version, &update_i8k)
|
END OBJ(i8k_version, &update_i8k)
|
||||||
obj->callbacks.print = &print_i8k_version;
|
obj->callbacks.print = &print_i8k_version;
|
||||||
|
17
src/linux.c
17
src/linux.c
@ -2229,24 +2229,27 @@ int get_entropy_poolsize(unsigned int *val)
|
|||||||
return 0;
|
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;
|
FILE *fp;
|
||||||
char path[128];
|
char path[128];
|
||||||
int state;
|
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)) {
|
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) {
|
if (fscanf(fp, "%d\n", &state) != 1) {
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return "failed";
|
snprintf(p, p_max_size, "failed");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return (state > 0) ? "frozen" : "free ";
|
snprintf(p, p_max_size, (state > 0) ? "frozen" : "free ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_diskio(void)
|
void update_diskio(void)
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#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 *);
|
char *get_ioscheduler(char *);
|
||||||
void print_laptop_mode(struct text_object *, char *, int);
|
void print_laptop_mode(struct text_object *, char *, int);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user